skip to Main Content

I have a docker image that is build from Dockerfile. It has pip installation inside with custom library. Now the image is used in docker-compose service.

requirements.txt

example-library-1
example-library-2

Dockerfile

FROM python:3.7-alpine
WORKDIR /code
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["flask", "run"]

docker build -t example_user/example_image .

docker-compose.yml

version: "3.9"
services:
  web:
    image: example_user/example_image
    ports:
      - "8000:5000"

When I have a new version for example-library-1, how do I update the docker-compose service to use the new library?

I had tried docker-compose up -d and docker-compose restart web but it does not check for new library version.

Is there a way to do this without docker-compose down and docker-compose up -d?

2

Answers


  1. You can add a build key to the compose file.

    services:
      web:
        image: example_user/example_image
        build:
          context: path/to/context
          dockerfile: path/to/Dockerfile
    

    Then you run compose with the build flag.

    docker compose up --build
    

    That said, compose does not have something like rolling updates. You need to stop to compose service and do up with the build flag in order to rebuild.

    If you need to rolling updates, you need to use a different operator, like swarm or Kubernetes.

    Login or Signup to reply.
  2. The docker-compose build flag is a good idea.

    After that I recommend to use –no-cache flag because the docker buildkit may cache some layer.

    Check here the documentation.

    Don’t forget to check the DOCKER_BUILDKIT environment variable too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search