容器重启策略不适用于Docker Compose(适用于Docker CLI)

时间:2019-01-14 11:29:45

标签: docker docker-compose

我有以下docker-compose.yml文件:

version: '3.5'
services:
  traefik:
    image: traefik:1.7-alpine
    ports:
      - 8881:80
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/etc/traefik/traefik.toml
    restart: always

然后从docker-compose up -d开始。如果我重新启动Docker引擎,则由此创建的容器将不会自动重新启动。

现在说我从这个容器开始:

docker run -d -p 8882:80 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v ./traefik.toml:/etc/traefik/traefik.toml \
    --restart always \
    traefik:1.7-alpine

如果我重新启动Docker引擎,它将自动启动。

Docker Compose版本在做什么?

编辑:

我使用不同的图像创建了另一个测试(只是为了确保它与Traefik无关),我相信我已将问题定位到了卷上:

Docker Compose:

version: '3.5'
services:
  traefik:
    image: containous/whoami
    volumes:
      - ./placeholder.txt:/placeholder.txt
    restart: always

Docker CLI:

docker run -d \
    -v ./placeholder.txt:/placeholder.txt \
    --restart always \
    containous/whoami

这是它们之间的区别(inspect)(左:撰写;右:cli):https://www.diffchecker.com/CC0WV3va

enter image description here enter image description here enter image description here

从Docker Compose版本中删除音量行可以“解决问题”。

0 个答案:

没有答案
相关问题