Docker 安装 Tomcat和MySQL

Docker 安装 Tomcat

转载链接

查找 Docker Hub 上的 Tomcat 镜像

root@UbuntuBase:/usr/local/docker/tomcat# docker search tomcat
NAME                           DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
tomcat                         Apache Tomcat is an open source implementa...   1550                [OK]                
dordoka/tomcat                 Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba...   43                                      [OK]
tomee                          Apache TomEE is an all-Apache Java EE cert...   42                  [OK]                
davidcaste/alpine-tomcat       Apache Tomcat 7/8 using Oracle Java 7/8 wi...   21                                      [OK]
consol/tomcat-7.0              Tomcat 7.0.57, 8080, "admin/admin"              16                                      [OK]
cloudesire/tomcat              Tomcat server, 6/7/8                            15                                      [OK]
maluuba/tomcat7                                                                9                                       [OK]
tutum/tomcat                   Base docker image to run a Tomcat applicat...   8                                       
jeanblanchard/tomcat           Minimal Docker image with Apache Tomcat         8                                       
andreptb/tomcat                Debian Jessie based image with Apache Tomc...   7                                       [OK]
bitnami/tomcat                 Bitnami Tomcat Docker Image                     5                                       [OK]
aallam/tomcat-mysql            Debian, Oracle JDK, Tomcat & MySQL              4                                       [OK]
antoineco/tomcat-mod_cluster   Apache Tomcat with JBoss mod_cluster            1                                       [OK]
maluuba/tomcat7-java8          Tomcat7 with java8.                             1                                       
amd64/tomcat                   Apache Tomcat is an open source implementa...   1                                       
primetoninc/tomcat             Apache tomcat 8.5, 8.0, 7.0                     1                                       [OK]
trollin/tomcat                                                                 0                                       
fabric8/tomcat-8               Fabric8 Tomcat 8 Image                          0                                       [OK]
awscory/tomcat                 tomcat                                          0                                       
oobsri/tomcat8                 Testing CI Jobs with different names.           0                                       
hegand/tomcat                  docker-tomcat                                   0                                       [OK]
s390x/tomcat                   Apache Tomcat is an open source implementa...   0                                       
ppc64le/tomcat                 Apache Tomcat is an open source implementa...   0                                       
99taxis/tomcat7                Tomcat7                                         0                                       [OK]
qminderapp/tomcat7             Tomcat 7                                        0

这里我们拉取官方的镜像

docker pull tomcat

等待下载完成后,我们就可以在本地镜像列表里查到 REPOSITORY 为 tomcat 的镜像。

运行容器:

docker run --name tomcat -p 8080:8080 -v $PWD/test:/usr/local/tomcat/webapps/test -d tomcat

命令说明:

  • -p 8080:8080:将容器的8080端口映射到主机的8080端口
  • -v $PWD/test:/usr/local/tomcat/webapps/test:将主机中当前目录下的test挂载到容器的/test
进入容器内部:docker exec -it tomcat /bin/bash

查看容器启动情况

root@UbuntuBase:/usr/local/docker/tomcat/webapps# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
38498e53128c        tomcat              "catalina.sh run"   2 minutes ago       Up 2 minutes        0.0.0.0:8080->8080/tcp   tomcat

通过浏览器访问


Docker 安装 MySQL


查找 Docker Hub 上的 MySQL 镜像

root@UbuntuBase:/usr/local/docker/mysql# docker search mysql
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                                                  MySQL is a widely used, open-source relati...   5177                [OK]                
mariadb                                                MariaDB is a community-developed fork of M...   1602                [OK]                
mysql/mysql-server                                     Optimized MySQL Server Docker images. Crea...   361                                     [OK]
percona                                                Percona Server is a fork of the MySQL rela...   298                 [OK]                
hypriot/rpi-mysql                                      RPi-compatible Docker Image with Mysql          72                                      
zabbix/zabbix-server-mysql                             Zabbix Server with MySQL database support       62                                      [OK]
centurylink/mysql                                      Image containing mysql. Optimized to be li...   53                                      [OK]
sameersbn/mysql                                                                                        48                                      [OK]
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server ...   36                                      [OK]
tutum/mysql                                            Base docker image to run a MySQL database ...   27                                      
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          17                                      [OK]
schickling/mysql-backup-s3                             Backup MySQL to S3 (supports periodic back...   16                                      [OK]
centos/mysql-57-centos7                                MySQL 5.7 SQL database server                   15                                      
linuxserver/mysql                                      A Mysql container, brought to you by Linux...   12                                      
centos/mysql-56-centos7                                MySQL 5.6 SQL database server                   6                                       
openshift/mysql-55-centos7                             DEPRECATED: A Centos7 based MySQL v5.5 ima...   6                                       
frodenas/mysql                                         A Docker Image for MySQL                        3                                       [OK]
dsteinkopf/backup-all-mysql                            backup all DBs in a mysql server                3                                       [OK]
circleci/mysql                                         MySQL is a widely used, open-source relati...   2                                       
cloudposse/mysql                                       Improved `mysql` service with support for ...   0                                       [OK]
astronomerio/mysql-sink                                MySQL sink                                      0                                       [OK]
ansibleplaybookbundle/rhscl-mysql-apb                  An APB which deploys RHSCL MySQL                0                                       [OK]
cloudfoundry/cf-mysql-ci                               Image used in CI of cf-mysql-release            0                                       
astronomerio/mysql-source                              MySQL source                                    0                                       [OK]
jenkler/mysql                                          Docker Mysql package                            0                                       

这里我们拉取官方的镜像

docker pull mysql

等待下载完成后,我们就可以在本地镜像列表里查到 REPOSITORY 为 mysql 的镜像

运行容器: sudo docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql

远程连接报错:ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be load

解决方法:

docker exec -it mysql /bin/bash

2.进入mysql

mysql -uroot -p

3.修改密码

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';



作者:吴国友
链接:https://www.jianshu.com/p/f641e4c5d7fd
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


docker run -p 3306:3306 --name mysql \
-v /usr/local/docker/mysql/conf:/etc/mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql

命令参数:

  • -p 3306:3306:将容器的3306端口映射到主机的3306端口
  • -v /usr/local/docker/mysql/conf:/etc/mysql:将主机当前目录下的 conf 挂载到容器的 /etc/mysql
  • -v /usr/local/docker/mysql/logs:/var/log/mysql:将主机当前目录下的 logs 目录挂载到容器的 /var/log/mysql
  • -v /usr/local/docker/mysql/data:/var/lib/mysql:将主机当前目录下的 data 目录挂载到容器的 /var/lib/mysql
  • -e MYSQL\_ROOT\_PASSWORD=123456:初始化root用户的密码

查看容器启动情况

root@UbuntuBase:/usr/local/docker/mysql# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
bc49c9de4cdf        mysql:latest        "docker-entrypoint..."   4 minutes ago       Up 4 minutes        0.0.0.0:3306->3306/tcp   mysql

使用客户端工具连接 MySQL


你可能感兴趣的:(Docker)