gpt4 book ai didi

docker - docker-compose用新标签构建

转载 作者:行者123 更新时间:2023-12-02 21:09:08 24 4
gpt4 key购买 nike

我有一个 docker 组成,看起来像:

version: '3.2'
services:
jobsaf-server:
build:
context: ./application
dockerfile: Dockerfile.production
container_name: jobsaf-server
env_file:
- ./application/.env
tty: true
depends_on:
- "redis"
- "mongo"
links:
- mongo
- redis
volumes:
- ./application/server:/var/www/app/jobsaf-website/server
- ./application/public/assets:/var/www/app/jobsaf-website/public/assets
- ./application/uploads:/var/www/app/jobsaf-website/uploads
- ./application/sitemaps:/var/www/app/jobsaf-website/sitemaps
- ./application/rss:/var/www/app/jobsaf-website/rss
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
nginx:
image: nginx:stable
tty: true
env_file:
- ./.env
environment:
- NGINX_HOST=${APP_HOST}
- NGINX_PORT=${APP_PORT}
- PUID=1001
- PGID=1001
- TZ=Asia/Kabul
links:
- jobsaf-server
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./nginx/ssl/star_jobs_af.pem:/etc/ssl/star_jobs_af.pem
- ./nginx/ssl/jobs.af.key:/etc/ssl/jobs.af.key
- ./nginx/ssl/star_jobs_af.crt:/etc/ssl/star_jobs_af.crt
ports:
- "80:80"
- "443:443"
mongo:
image: mongo:latest
container_name: mongo
tty: true
env_file:
- ./.env
volumes:
- "db-data:/data/db"
environment:
- MONGO_INITDB_ROOT_USERNAME=${DB_USER}
- MONGO_INITDB_ROOT_PASSWORD=${DB_PASS}
- MONGO_INITDB_DATABASE=admin
ports:
- "0.0.0.0:27017:27017"
redis:
image: redis
container_name: redis
tty: true
volumes:
db-data:
# - /data/db
networks:
front-tier:
back-tier:


默认情况下,它会构建 jobsaf-server:latest

我想要的是保留旧标签并构建新标签。

可以说,在构建图像时,我应该传递与此类似的内容
docker-compose -f docker-compose.production --tag=1.0.1
上面的命令应该为我和带有 jobsaf-server:1.0.1标签的图像构建

真的有可能产生这样的结果吗?
还是有其他替代解决方案

提前致谢。

注意:我想保留旧图像,以防万一我的新图像出了问题,那么我可以使用旧图像。

最佳答案

version: '3.2'
services:
jobsaf-server:
image: jobsaf-server:${TAG}
build:
context: ./application
dockerfile: Dockerfile.production
...

提供标签的最佳方法是使用.env文件,如下所示:
TAG=1.0.1

Docker-compose会自动选择它。

关于docker - docker-compose用新标签构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56082506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com