要在 docker-compose 的配置文件中添加 --pull always,可以在服务的定义中添加 'image:xxx',然后在该行下面添加 'image:xxx:latest' 和 'image:xxx:$(git rev-parse --short HEAD)' 两行。这样,每次构建时会自动拉取最新的镜像,并将其标记为最新的和当前的 git 版本。例如:

services:
  web:
    image: myapp:latest
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    image: myapp:latest
    image: myapp:$(git rev-parse --short HEAD)
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code

在这个例子中,每次构建时,Docker 会拉取最新的 'myapp' 镜像,并将其标记为 'latest' 和当前 git 的短哈希值。

Docker Compose 配置文件添加 --pull always 详解

原文地址: https://www.cveoy.top/t/topic/nTrD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录