[root@hspEdu01 nginx]# docker pull nginx Using default tag: latest Trying to pull repository docker.io/library/nginx ... latest: Pulling from docker.io/library/nginx 69692152171a: Already exists 30afc0b18f67: Pull complete 596b1d696923: Pull complete febe5bd23e98: Pull complete 8283eee92e2f: Pull complete 351ad75a6cfa: Pull complete Digest: sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750 Status: Downloaded newer image for docker.io/nginx:latest [root@hspEdu01 nginx]# ls conf logs www [root@hspEdu01 nginx]# cd conf/ [root@hspEdu01 conf]# ls nginx.conf [root@hspEdu01 conf]# cd ../ [root@hspEdu01 nginx]# cd ../ [root@hspEdu01 ~]# rm -rf nginx/ [root@hspEdu01 ~]# ls anaconda-ks.cfg data data2 initial-setup-ks.cfg mysql 公共 模板 视频 图片 文档 下载 音乐 桌面 [root@hspEdu01 ~]# docker run --name nginx-test -p 80:80 -d nginx 608ed67163e091695eb14f964cff6f4d24f2818275845f34254eff49e24fe770 [root@hspEdu01 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS 608ed67163e0 nginx "/docker-entrypoin..." 4 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp 760a2956258e a8e34 "java -jar app.jar" About an hour ago Up About an hour 0.0.0.0:8010->8010/tcp 95628d5d89c5 mysql:5.7 "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tc [root@hspEdu01 ~]# mkdir -p /root/nginx/www /root/nginx/logs /root/nginx/conf [root@hspEdu01 ~]# cd nginx/ [root@hspEdu01 nginx]# cd conf/ [root@hspEdu01 conf]# ls [root@hspEdu01 conf]# docker cp 608e:/etc/nginx/nginx.conf /root/nginx/conf [root@hspEdu01 conf]# ls nginx.conf [root@hspEdu01 conf]# docker rm -f 608e 608e [root@hspEdu01 conf]# docker run -d -p 80:80 --name nginx-web -v /root/nginx/www:/usr/share/nginx/html -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/logs:/var/log/nginx nginx 987bc07bc4eb474332766dfe6409d957e07bf94fc24153222cf8bf99147df717 [root@hspEdu01 conf]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 987bc07bc4eb nginx "/docker-entrypoin..." 10 seconds ago Exited (1) 9 seconds ago nginx-web 760a2956258e a8e34 "java -jar app.jar" About an hour ago Up About an hour 0.0.0.0:8010->8010/tcp adoring_pare 95628d5d89c5 mysql:5.7 "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql [root@hspEdu01 conf]# docker logs -f 987b /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2021/06/12 02:26:39 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (13: Permission denied) [root@hspEdu01 conf]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 987bc07bc4eb nginx "/docker-entrypoin..." About a minute ago Exited (1) About a minute ago nginx-web 760a2956258e a8e34 "java -jar app.jar" About an hour ago Up About an hour 0.0.0.0:8010->8010/tcp adoring_pare 95628d5d89c5 mysql:5.7 "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql [root@hspEdu01 conf]# docker rm -f 987 987 [root@hspEdu01 conf]# docker run -d -p 80:80 --name nginx-web -v /root/nginx/www:/usr/share/nginx/html -v /root/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx/logs:/var/log/nginx --privileged=true nginx 6593ed8866071e1865217f58c627005aa8f3e9b3c8db6f5ff1aec22653503d1a [root@hspEdu01 conf]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6593ed886607 nginx "/docker-entrypoin..." 5 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp nginx-web 760a2956258e a8e34 "java -jar app.jar" About an hour ago Up About an hour 0.0.0.0:8010->8010/tcp adoring_pare 95628d5d89c5 mysql:5.7 "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql [root@hspEdu01 conf]# cd ../ [root@hspEdu01 nginx]# cd www/ [root@hspEdu01 www]# touch a.html [root@hspEdu01 www]# vim a.html [root@hspEdu01 www]#
access_log /var/log/nginx/access.log main; upstream myserver { server 118.195.164.41:8080 weight=1; server 118.195.164.41:8888 weight=10; server 118.195.164.41:8881 weight=15; server 118.195.164.41:8010 weight=20; }
access_log /var/log/nginx/access.log main; upstream myserver { ip_hash; server 118.195.164.41:8080 ; server 118.195.164.41:8888 ; server 118.195.164.41:8881 ; server 118.195.164.41:8010 ; }
[root@VM-0-15-centos conf]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a386923c309b bcf990bea01a "catalina.sh run" 22 hours ago Up 22 hours 0.0.0.0:8010->8080/tcp tomcat8081 5dbbb4db6e00 bcf990bea01a "catalina.sh run" 42 hours ago Up 42 hours 0.0.0.0:8881->8080/tcp tomcat-8881 216a2e8f1c90 bcf990bea01a "catalina.sh run" 43 hours ago Up 43 hours 0.0.0.0:8888->8080/tcp tomcat-8888 8499b0e39d0f bcf990bea01a "catalina.sh run" 43 hours ago Up 43 hours 0.0.0.0:8080->8080/tcp mytomcat 7dd71eee737f mysql:5.7 "docker-entrypoint..." 2 days ago Up 2 days 0.0.0.0:3306->3306/tcp, 33060/tcp mysql 52aa02d195d9 nginx "/docker-entrypoin..." 2 days ago Up 39 seconds 0.0.0.0:80->80/tcp nginx-web [root@VM-0-15-centos conf]# vim nginx.conf [root@VM-0-15-centos conf]# cat nginx.conf
access_log /var/log/nginx/access.log main; upstream myserver { server 118.195.164.41:8080 ; server 118.195.164.41:8888 ; server 118.195.164.41:8881 ; server 118.195.164.41:8010 ; }