一看必会系列:docker-compose简单部署nginx

来源:本站原创 Docker 超过207 views围观 0条评论

task
service
stack

安装
  719  sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  720  sudo chmod +x /usr/local/bin/docker-compose
  721  docker-compose -h
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
root@docker:~# docker-compose –version
docker-compose version 1.23.2, build 1110ad01
root@docker:~#

目录分布如下
└── dweb
    ├── docker-compose.yml
    ├── nginx01
    │   └── index.html
    └── nginx02
        ├── 1
        └── index.html

配置文件如下docker-compose.yml
root@docker:/opt/docker-compose/dweb# cat docker-compose.yml
nginx01:
    image: reg.ccie.wang/library/nginx:1.15.9 
    volumes:
         – ./nginx01:/usr/share/nginx/html   #将本地目录挂载到 容器内的目录/usr/share/nginx/html
    container_name: nginx01
    ports:
                – "80:80"                     #将本地端口和容器内端口映射 。前面是本地端口。后面是容器内端口
nginx02:
    image: reg.ccie.wang/library/nginx:1.15.9
    volumes:
          – ./nginx02:/usr/share/nginx/html
    container_name: nginx02
    ports:
                – "81:80"

在docker-compose.yml目录运行  -d 是后台运行
docker-compose up -d
docker-compose down -v  #停止。并删除所有卷
docker-compose restart #重启服务

root@docker:/opt/docker-compose/dweb# docker-compose up -d
Creating nginx01 … done
Creating nginx02 … done

               
验证端口
root@docker:/opt/docker-compose/dweb# netstat -ntlp |grep docker
tcp6       0      0 :::80                   :::*                    LISTEN      24251/docker-proxy 
tcp6       0      0 :::81                   :::*                    LISTEN      24237/docker-proxy 
root@docker:/opt/docker-compose/dweb#

验证docker进程
root@docker:/opt/docker-compose/dweb# docker ps
CONTAINER ID        IMAGE                                COMMAND                  CREATED             STATUS              PORTS                NAMES
5f9a63957028        reg.ccie.wang/library/nginx:1.15.9   "nginx -g ‘daemon of…"   34 seconds ago      Up 31 seconds       0.0.0.0:80->80/tcp   nginx01
cfb46b4ea3d3        reg.ccie.wang/library/nginx:1.15.9   "nginx -g ‘daemon of…"   34 seconds ago      Up 31 seconds       0.0.0.0:81->80/tcp   nginx02

生成index.html文件验证web可用性
root@docker:/opt/docker-compose/dweb# cd nginx01
root@docker:/opt/docker-compose/dweb/nginx01# vim index.html
root@docker:/opt/docker-compose/dweb/nginx01# cd ..
root@docker:/opt/docker-compose/dweb# vim nginx02/index.html
root@docker:/opt/docker-compose/dweb#

结果正常
root@docker:/opt/docker-compose/dweb# curl localhost:81
002
root@docker:/opt/docker-compose/dweb# curl localhost:80
001
root@docker:/opt/docker-compose/dweb#

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=4079转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点

暂时还木有人评论,坐等沙发!
发表评论

您必须 [ 登录 ] 才能发表留言!