简体   繁体   English

使用docker hub时如何强制docker-compose下载新镜像?

[英]How to force docker-compose to download a new image when using docker hub?

I have a docker-compose.yml file which takes the image svka4019/notes2:latest from the docker hub.我有一个 docker-compose.yml 文件,它从 docker hub 获取图像 svka4019/notes2:latest。 However, if I change the image build it and push it, when I run docker-compose it just uses the one it has already downloaded before.但是,如果我更改镜像构建并推送它,当我运行 docker-compose 时,它​​只会使用它之前已经下载的镜像。 Here is the docker-compose.yml:这是 docker-compose.yml:

springboot-docker-compose-app-container: 
    image: svka4019/notes2:latest
    ports:
      - "80:5001"
    depends_on:
    - friendservice
    networks:
    - mynet
    container_name: base_notes
  friendservice:
    build: ./Pirmas
    command: python app.py
    ports:
    - 5000:5000
    container_name: friend
    networks:
    - mynet
    
networks:
    mynet:

And the command I use for building and running: docker-compose up --build -d .以及我用于构建和运行的命令: docker-compose up --build -d For updating the image in docker-hub I use:为了更新 docker-hub 中的图像,我使用:

docker build -t svka4019/notes2
docker push svka4019/notes2

If I use methods as no-cache it just rebuilds friendService container and skips the base one.如果我使用无缓存的方法,它只会重建friendService 容器并跳过基本容器。

As @DazWilkin pointed out in the comments, using latest tag should be used carefully.正如@DazWilkin 在评论中指出的那样,应谨慎使用最新标签。 Not only can it introduce bugs in your app if latest comes with BC breaks, but it also doesn't indicate that a new update must be performed on your machine if you already have an image 'latest'.如果最新的 BC 中断,它不仅会在您的应用程序中引入错误,而且如果您已经拥有“最新”图像,它也不表示必须在您的计算机上执行新的更新。

In your case, what you have to do should you want to keep using latest, is to simply call:在你的情况下,如果你想继续使用最新的,你必须做的就是简单地调用:

docker-compose pull

In case you are building your own image, then you must do:如果您要构建自己的映像,则必须执行以下操作:

docker-compose build --pull

The latter will tell docker-compose to first pull the base image before building your custom image.后者会告诉 docker-compose 在构建自定义镜像之前先拉取基础镜像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 docker-compose 下载私有镜像(本地) - How to download private image (locally) using docker-compose 使用docker-compose运行分布式气流架构时如何将新用户添加到docker镜像 - How to add new user to docker image when running distributed airflow architecture using docker-compose 使用docker-compose,如何将我的图像共享到docker-hub? - Using docker-compose, how do I share my image to docker-hub? 如何使用 docker-compose 强制时间进入 Docker 容器 - How to force time into Docker container using docker-compose 如何在使用docker-compose时为mongodb图像添加--auth? - how to add --auth for mongodb image when using docker-compose? 如何将带有 docker-compose 的多个 docker 图像推送到 docker 集线器? - How to push multiple docker images with docker-compose to docker hub? docker-compose何时构建本地映像,何时从docker hub提取? - When does docker-compose build a local image and when does it pull from docker hub? `docker-compose` 强制运行旧图像 - `docker-compose` force run old image 如何使用 Docker-compose 构建 Loki 服务器 Docker 映像 - How to build a Loki server Docker image using Docker-compose 如何使用正则表达式在docker-compose文件中指定docker镜像 - How to specify a docker image in docker-compose file using regex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM