用Docker实现nginx多端口

一.安装docker

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

[root@bogon ~]#yum -y install docker

[root@bogon ~]#systemctl start docker

[root@bogon ~]#systemctl enable docker

 

  1. 下载httpd镜像

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

 

  1. 运行容器并指定端口

[root@localhost ~]# docker run -it -p 8001:80 docker.io/nginx /bin/bash

root@c8931c0b8359:/# nginx

 

4查看容器状态

[root@localhost ~]# docker container ls     或者 docker ps -a

 

进入容器里面

[root@localhost ~]# docker attach 9b

root@9b38a1021078:/#

 

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

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

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

 

root@c8931c0b8359:/usr/share/nginx/html# ls

50x.html  index.html

root@c8931c0b8359:/usr/share/nginx/html# echo 'welocome to beijing' > index.html

root@c8931c0b8359:/usr/share/nginx/html# [root@localhost ~]#

[root@localhost ~]# curl 192.168.30.24:8001

welocome to beijing

 

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

[root@localhost ~]# docker run -it -p 8002:80 docker.io/nginx /bin/bash

root@9b38a1021078:/# nginx

root@9b38a1021078:/# [root@localhost ~]#

[root@localhost ~]# 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

[root@localhost ~]# docker attach 9b

root@9b38a1021078:/# cd /usr/share/nginx/html/

root@9b38a1021078:/usr/share/nginx/html# ls

50x.html  index.html

root@9b38a1021078:/usr/share/nginx/html# echo 'welocome to shandong' > index.html

root@9b38a1021078:/usr/share/nginx/html# [root@localhost ~]#

[root@localhost ~]# curl 192.168.30.24:8002

welocome to shandong

[root@localhost ~]# 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

 

posted @ 2019-05-29 15:04  #赵程#  阅读(2002)  评论(0编辑  收藏  举报