使用docker部署tomcat服务器
1、拉去tomcat镜像
[root@localhost yum.repos.d]# sudo docker pull docker.io/tomcat:9
9: Pulling from library/tomcat
de44b265507a: Pull complete
4c2afd91a87d: Pull complete
89e9bbcfa697: Pull complete
11be3e613582: Pull complete
1b9d1e181a2a: Pull complete
ffd7da68d2ba: Pull complete
4f4fb700ef54: Pull complete
cff7298967c0: Pull complete
Digest: sha256:b19c830294642c0dd863346fbecd190e000b4164df5cc760d1b435012db0a0b6
Status: Downloaded newer image for tomcat:9
docker.io/library/tomcat:9
2、查看tomcat镜像
[root@localhost yum.repos.d]# docker images tomcat
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9 f05fe3cd4f92 10 days ago 470MB
3、通过docker服务创建tomcat守护式容器
[root@localhost yum.repos.d]# docker run -di -p 80:8080 --name=tomcat001 docker.io/tomcat:9
0444152863f24d3d03ad8d87ae217b570a97f6cceaa69b6b27e06881eccc29d0
4、通过tocker服务查看tomcat容器状态,当tomcat容器的状态显示为up时,表明tomcat容器已经启动成功
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0444152863f2 tomcat:9 "catalina.sh run" 9 seconds ago Up 9 seconds 0.0.0.0:80->8080/tcp, :::80->8080/tcp tomcat001
四、通过docker部署mysql数据库
1、拉去mysql镜像
[root@localhost yum.repos.d]# docker pull docker.io/mysql:5.7
5.7: Pulling from library/mysql
20e4dcae4c69: Pull complete
1c56c3d4ce74: Pull complete
e9f03a1c24ce: Pull complete
68c3898c2015: Pull complete
6b95a940e7b6: Pull complete
90986bb8de6e: Pull complete
ae71319cb779: Pull complete
ffc89e9dfd88: Pull complete
43d05e938198: Pull complete
064b2d298fba: Pull complete
df9a4d85569b: Pull complete
Digest: sha256:4bc6bc963e6d8443453676cae56536f4b8156d78bae03c0145cbe47c2aad73bb
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
2、查看镜像
[root@localhost yum.repos.d]# docker images mysql
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 5107333e08a8 13 months ago 501MB
3、通过docker服务创建mysql守护式容器。这里已经设置了用户和用户密码。
[root@localhost yum.repos.d]# docker run -di --name=mysql001 -p 33506: -e MYSQL_ROOT_PASSWORD=123456 docker.io/mysql:5.7
4、通过docker服务查看mysql容器状态,当容器的状态显示为up时,表明容器已经启动成功
[root@localhost yum.repos.d]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8bf430c86754 mysql:5.7 "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 3306/tcp, 33060/tcp, 0.0.0.0:32768->33506/tcp, :::32768->33506/tcp mysql001
0444152863f2 tomcat:9 "catalina.sh run" 3 minutes ago Up 3 minutes 0.0.0.0:80->8080/tcp, :::80->8080/tcp tomcat001
5、进入mysql容器
[root@localhost yum.repos.d]# docker exec -it 8bf430c86754 bash
bash-4.2# mysql -uroot -p123456
6、然后就可以随便进行操作了