img

Docker部署Nginx

# 搜索镜像 docker search nginx
# 下载镜像 docker pull nginx
# 启动镜像 docker run -d -p 2580:80 nginx (把外部服务器2580 端口映射到nginx的80端口)

image-20210904235227748

端口映射外网访问

image-20210904235624981

进入nginx内部

[root@iZbp17g2ontiv6b4tu0incZ ~]# docker stop 66d211897c38
66d211897c38
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker exec -it myNginx /bin/bash
Error response from daemon: Container 66d211897c38085f902f3d4ae3967b4330d5234290de8603ccf5b65d5db39026 is not running
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker run -d --name flnginx -p 2580:80 nginx
3b3f6483fe4fc94b6b8d3ab1f5b72fcaccf4186a10fa675f02720948f0140fbc
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker exec -it flnginx /bin/bash
root@3b3f6483fe4f:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@3b3f6483fe4f:/# cd /etc/nginx/
root@3b3f6483fe4f:/etc/nginx# ls
conf.d fastcgi_params mime.types modules nginx.conf scgi_params uwsgi_params


Docker部署Tomcat

[root@iZbp17g2ontiv6b4tu0incZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 822b7ec2aaf2 32 hours ago 133MB
mysql 8.0 0716d6ebcc1a 33 hours ago 514MB
tomcat latest 266d1269bb29 2 weeks ago 668MB
nginx <none> dd34e67e3371 2 weeks ago 133MB
mysql 5.7 8cf625070931 6 weeks ago 448MB
hello-world latest d1165f221234 6 months ago 13.3kB
centos latest 300e315adb2f 9 months ago 209MB
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker run -d -:2333:8080 tomcat
unknown shorthand flag: ':' in -:2333:8080
See 'docker run --help'.
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker run -d -p 2333:8080 tomcat
6edce5be34f1f66e5962b1a3364a87898b67202b9183adedaf0bbf58bd8830ed
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker exec -it tomcat /bin/bash
Error: No such container: tomcat
[root@iZbp17g2ontiv6b4tu0incZ ~]# docker exec -it 6edce5be34f1f66e5962b1a3364a87898b67202b9183adedaf0bbf58bd8830ed /bin/bash
root@6edce5be34f1:/usr/local/tomcat# ls
BUILDING.txt LICENSE README.md RUNNING.txt conf logs temp webapps.dist
CONTRIBUTING.md NOTICE RELEASE-NOTES bin lib native-jni-lib webapps work
root@6edce5be34f1:/usr/local/tomcat# cd bin
root@6edce5be34f1:/usr/local/tomcat/bin# ls
bootstrap.jar catalina.sh commons-daemon-native.tar.gz configtest.sh digest.sh setclasspath.sh startup.sh tool-wrapper.sh
catalina-tasks.xml ciphers.sh commons-daemon.jar daemon.sh makebase.sh shutdown.sh tomcat-juli.jar version.sh
root@6edce5be34f1:/usr/local/tomcat/bin# sh startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/openjdk-11
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
root@6edce5be34f1:/usr/local/tomcat/bin#
# 发布一个默认项目
root@6edce5be34f1:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@6edce5be34f1:/usr/local/tomcat#

image-20210905001956503

熟悉的界面出现了

image-20210905001816159

Docker部署Mysql(容器数据卷挂载)


# 运行容器做数据挂载
docker run -d -p 3306:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysqlTest mysql

远程连接测试

image-20210905164106197

image-20210905164553999

进入Mysql

[root@fl02 ~]# docker exec -it ac8fa5b5d731 /bin/bash
root@ac8fa5b5d731:/# mysql -uroot -p -h localhost
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
# 显示数据库正常
mysql> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| Test |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)

mysql> use Test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables
-> ;
+----------------+
| Tables_in_Test |
+----------------+
| test |
+----------------+
1 row in set (0.00 sec)