jenkins
CI/CD
docker build
docker run

执行脚本,打包项目镜像

image.png

启动容器并挂载数据卷

  1. mkdir -p /dockerapp/nginx/www /dockerapp/ngxin/conf /dockerapp/nginx/logs
  2. docker run -it -p 8081:80 --name dockerapp01 -v /dockerapp/nginx/conf:/etc/nginx 4f361dbcbce5 /bin/bash

无法访问

  1. curl localhost:8081
  2. curl: (56) Recv failure: Connection reset by peer

防火墙状态正常

  1. systemctl status firewalld
  2. firewalld.service - firewalld - dynamic firewall daemon
  3. Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
  4. Active: active (running) since Tue 2021-01-05 17:48:36 CST; 8 months 28 days ago
  5. Docs: man:firewalld(1)
  6. Main PID: 1834 (firewalld)
  7. Tasks: 2
  8. Memory: 4.9M
  9. CGroup: /system.slice/firewalld.service
  10. └─1834 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
  11. Oct 01 20:45:40 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It... it now.
  12. Oct 01 20:45:41 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' fa...chain?).
  13. Oct 01 20:45:41 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' fa...chain?).
  14. Oct 02 19:06:58 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It... it now.
  15. Oct 02 19:06:59 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' fa...chain?).
  16. Oct 02 19:06:59 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' fa...chain?).
  17. Oct 03 20:30:03 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-799426d70aa2 -o br-799426d7...chain?).
  18. Oct 04 10:02:19 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-9fb064c034b1 -o br-9fb064c0...chain?).
  19. Oct 04 10:18:09 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-0096a971fd2c -o br-0096a971...chain?).
  20. Oct 04 11:04:50 iZm5e23n3ueobwkjtfartxZ firewalld[1834]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-0350d84612be -o br-0350d846...chain?).
  21. Hint: Some lines were ellipsized, use -l to show in full.
  22. [root@--- financial-innovation-h5]#
  1. 在nginx镜像基础之上把自己的前端项目打包成镜像
  2. 运行镜像,启动容器
  3. 浏览器访问
    1. FROM nginx:1.17.3
    2. ADD h5.tar.gz /usr/share/nginx/html

步骤上没有任何问题,没有参考任何文档,实测发现容器启动了,但是容器里面的nginx服务并没有启动,导致内网和浏览器访问不同,
解决:
进入容器,启动服务

  1. cd /etc/init.d
  2. .nginx start

浏览器即可访问

启动容器跟启动容器内的服务是两码事

守护态运行

  1. docker run -d ubuntu:18.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"

问题扩展 怎么接上Jenkins,完成CI/CD