一看必會系列:docker-compose簡單部署nginx

來源:本站原創 Docker 超過224 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
[email protected]:~# docker-compose –version
docker-compose version 1.23.2, build 1110ad01
[email protected]:~#

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

配置文件如下docker-compose.yml
[email protected]:/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 #重啟服務

[email protected]:/opt/docker-compose/dweb# docker-compose up -d
Creating nginx01 … done
Creating nginx02 … done

               
驗證端口
[email protected]:/opt/docker-compose/dweb# netstat -ntlp |grep docker
tcp6       0      0 :::80                   :::*                    LISTEN      24251/docker-proxy 
tcp6       0      0 :::81                   :::*                    LISTEN      24237/docker-proxy 
[email protected]:/opt/docker-compose/dweb#

驗證docker進程
[email protected]:/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可用性
[email protected]:/opt/docker-compose/dweb# cd nginx01
[email protected]:/opt/docker-compose/dweb/nginx01# vim index.html
[email protected]:/opt/docker-compose/dweb/nginx01# cd ..
[email protected]:/opt/docker-compose/dweb# vim nginx02/index.html
[email protected]:/opt/docker-compose/dweb#

結果正常
[email protected]:/opt/docker-compose/dweb# curl localhost:81
002
[email protected]:/opt/docker-compose/dweb# curl localhost:80
001
[email protected]:/opt/docker-compose/dweb#

文章出自:CCIE那點事 http://www.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4079轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
暫時還木有人評論,坐等沙發!
發表評論

您必須 [ 登錄 ] 才能發表留言!

?
?
萌宠夺宝游戏