docker-compose重启容器测试

docker-compose重启容器测试

容器准备

root@node2:~# docker run -itd nginx
root@node2:~# docker exec -it bab bash
root@bab98093d91e:/# echo web1 >/usr/share/nginx/html/index.html
root@bab98093d91e:/# curl localhost
web1
root@bab98093d91e:/# exit
exit
root@node2:~# docker commit bab98093d91e nginx:web1

root@node2:~# docker exec -it bab bash
root@bab98093d91e:/# echo web2 >/usr/share/nginx/html/index.html
root@bab98093d91e:/# curl localhost
web2
root@bab98093d91e:/# exit
exit
root@node2:~# docker commit bab98093d91e nginx:web2

启动测试

root@node2:~# cat docker-compose.yaml
services:
  nginx:
    image: nginx:web2
    ports:
      - "80:80"
  nginx2:
    image: nginx:web2
    ports:
      - "8080:80"
root@node2:~# docker-compose up -d
[+] Running 2/2
 ✔ Container root-nginx-1   Started
 ✔ Container root-nginx2-1  Started 
 
root@node2:~# curl localhost
web2
root@node2:~# curl localhost:8080
web2

改变镜像测试

root@node2:~# cat docker-compose.yaml
services:
  nginx:
    image: nginx:web1
    ports:
      - "80:80"
  nginx2:
    image: nginx:web2
    ports:
      - "8080:80"
root@node2:~# docker restart nginx          # 执行重启,不会更新服务
root@node2:~# curl localhost
web2

root@node2:~# docker-compose up -d     
[+] Running 2/2
 ✔ Container root-nginx-1   Started     # 更新变化的服务,并重启
 ✔ Container root-nginx2-1  Running     # 没有变化的服务无变化
 
 
root@node2:~# docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS 
a7e028aaf544   nginx:web2             "/docker-entrypoint.…"   7 minutes ago    Up 6 minutes 
8902b46d5c05   nginx:web2             "/docker-entrypoint.…"   12 minutes ago   Up 12 minutes

改变配置测试

root@node2:~# cat web.conf
server {
    listen       8880;
    server_name  local;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

root@node2:~# cat docker-compose.yaml
services:
  nginx:
    image: nginx:web1
    volumes:
      - ./web.conf:/etc/nginx/conf.d/web.conf
    ports:
      - "80:80"
      - "8880:8880"
  nginx2:
    image: nginx:web2
    ports:
      - "8080:80"
root@node2:~# docker-compose up -d  # 
[+] Running 2/2
 ✔ Container root-nginx2-1  Running
 ✔ Container root-nginx-1   Started
root@node2:~# docker exec -it root-nginx-1 curl localhost:8880
web1

重启所有镜像–force-recreate

root@node2:~# docker-compose up -d --force-recreate   # 
[+] Running 2/2
 ✔ Container root-nginx2-1  Started
 ✔ Container root-nginx-1   Started  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值