当前位置: 代码迷 >> 综合 >> How to manage nginx based on docker,part I
  详细解决方案

How to manage nginx based on docker,part I

热度:53   发布时间:2023-12-15 00:03:01.0

??今天我们来简要演示一下,如何基于docker部署nginx。

run nginx:


[root@node01 ~]# docker run -d -p 80:80 -p 443:443 -v /nginx/nginx.conf:/etc/nginx/nginx.conf:ro -v /nginx/default.conf:/etc/nginx/conf.d/default.conf -v /html/:/html/ -v /cert:/cert nginx:latest
[root@node01 ~]# docker ps 
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                                      NAMES
01eb112d6fb4        nginx:latest                         "nginx -g 'daemon of…"   16 minutes ago      Up 16 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   dazzling_mahavira
ed2ff70e1376        47.x.y.192:5000/center:19.7.8.3   "java -Djava.securit…"   4 weeks ago         Up 11 minutes       0.0.0.0:8083->8083/tcp, 8092/tcp           awesome_mestorf
c041ddabdd2e        registry:2                           "/entrypoint.sh /etc…"   5 months ago        Up 2 months         0.0.0.0:5000->5000/tcp                     registry2
[root@node01 ~]# 

??可以看到nginx已经启动成功。

view logger for nginx

??可以用如下命令查看nginx日志。

[root@node01 ~]# docker logs -f 01eb112d6fb4
2019/08/06 02:25:47 [warn] 1#1: the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/default.conf:5
nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/default.conf:5
2019/08/06 02:25:47 [warn] 1#1: the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/default.conf:37
nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /etc/nginx/conf.d/default.conf:37

restart nginx

??可以用如下命令重启nginx。

[root@node01 ~]# docker ps 
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                                      NAMES
01eb112d6fb4        nginx:latest                         "nginx -g 'daemon of…"   26 minutes ago      Up 26 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   dazzling_mahavira
ed2ff70e1376        47.x.y.192:5000/center:19.7.8.3   "java -Djava.securit…"   4 weeks ago         Up 21 minutes       0.0.0.0:8083->8083/tcp, 8092/tcp           awesome_mestorf
c041ddabdd2e        registry:2                           "/entrypoint.sh /etc…"   5 months ago        Up 2 months         0.0.0.0:5000->5000/tcp                     registry2
[root@node01 ~]# docker restart 01eb112d6fb4
01eb112d6fb4
[root@node01 ~]# 

stop nginx

??可以用如下命令关闭nginx。

[root@node01 ~]# docker stop 01eb112d6fb4
01eb112d6fb4
[root@node01 ~]#

start nginx

??可以用如下命令启动nginx。

[root@node01 ~]# docker start 01eb112d6fb4
01eb112d6fb4
[root@node01 ~]#
  相关解决方案