运维开发网

用Docker实现nginx多端口

运维开发网 https://www.qedev.com 2020-07-05 18:31 出处:网络 作者:运维开发网整理
一.安装docker 需要阿里的epel源,需要联网 [[email protected] ~]#yum -y install docker [[email protected] ~]#systemctl start docker [[email protected] ~]#systemctl enable docker   下载httpd镜像 Docker pull http:2.4.27-al

一.安装docker

需要阿里的epel源,需要联网

[[email protected] ~]#yum -y install docker

[[email protected] ~]#systemctl start docker

[[email protected] ~]#systemctl enable docker

 

  1. 下载httpd镜像

Docker pull http:2.4.27-alpine     如果镜像本地/root下存放了,可以用docker road < nginx

 

  1. 运行容器并指定端口

[[email protected] ~]# docker run -it -p 8001:80 docker.io/nginx /bin/bash

[email protected]:/# nginx

 

4查看容器状态

[[email protected] ~]# docker container ls     或者 docker ps -a

 

进入容器里面

[[email protected] ~]# docker attach 9b

[email protected]:/#

 

5.在容器安装目录下创建网页

Yum安装地址放在/usr/share/nginx/html

源码安装地址放在/usr/local/nginx/htm

 

[email protected]:/usr/share/nginx/html# ls

50x.html  index.html

[email protected]:/usr/share/nginx/html# echo ‘welocome to beijing‘ > index.html

[email protected]:/usr/share/nginx/html# [[email protected] ~]#

[[email protected] ~]# curl 192.168.30.24:8001

welocome to beijing

 

6在容器里可以创建多个端口:8002

[[email protected] ~]# docker run -it -p 8002:80 docker.io/nginx /bin/bash

[email protected]:/# nginx

[email protected]:/# [[email protected] ~]#

[[email protected] ~]# docker container ls

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES

9b38a1021078        docker.io/nginx     "/bin/bash"         18 seconds ago      Up 16 seconds       0.0.0.0:8002->80/tcp   stoic_goldwasser

c8931c0b8359        docker.io/nginx     "/bin/bash"         13 minutes ago      Up 13 minutes       0.0.0.0:8001->80/tcp   kind_booth

[[email protected] ~]# docker attach 9b

[email protected]:/# cd /usr/share/nginx/html/

[email protected]:/usr/share/nginx/html# ls

50x.html  index.html

[email protected]:/usr/share/nginx/html# echo ‘welocome to shandong‘ > index.html

[email protected]:/usr/share/nginx/html# [[email protected] ~]#

[[email protected] ~]# curl 192.168.30.24:8002

welocome to shandong

[[email protected] ~]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES

9b38a1021078        docker.io/nginx     "/bin/bash"         2 minutes ago       Up 2 minutes        0.0.0.0:8002->80/tcp   stoic_goldwasser

c8931c0b8359        docker.io/nginx     "/bin/bash"         15 minutes ago      Up 15 minutes       0.0.0.0:8001->80/tcp   kind_booth

0

精彩评论

暂无评论...
验证码 换一张
取 消