how to get docker-compose to use the latest image from repository

后端 未结 10 1377
栀梦
栀梦 2021-01-30 07:51

I don\'t know what I\'m doing wrong, but I simply cannot get docker-compose up to use the latest image from our registry without first removing the old containers f

相关标签:
10条回答
  • 2021-01-30 08:22

    Option down resolve this problem

    I run my compose file:

    docker-compose -f docker/docker-compose.yml up -d

    then I delete all with down --rmi all

    docker-compose -f docker/docker-compose.yml down --rmi all

    Stops containers and removes containers, networks, volumes, and images
    created by `up`.
    
    By default, the only things removed are:
    
    - Containers for services defined in the Compose file
    - Networks defined in the `networks` section of the Compose file
    - The default network, if one is used
    
    Networks and volumes defined as `external` are never removed.
    
    Usage: down [options]
    
    Options:
        --rmi type          Remove images. Type must be one of:
                            'all': Remove all images used by any service.
                            'local': Remove only images that don't have a custom tag
                            set by the `image` field.
        -v, --volumes       Remove named volumes declared in the `volumes` section
                            of the Compose file and anonymous volumes
                            attached to containers.
        --remove-orphans    Remove containers for services not defined in the
                            Compose file
    
    0 讨论(0)
  • 2021-01-30 08:22

    I am using following command to get latest images

    sudo docker-compose down -rmi all

    sudo docker-compose up -d

    0 讨论(0)
  • 2021-01-30 08:26

    I spent half a day with this problem. The reason was that be sure to check where the volume was recorded.

    volumes: - api-data:/src/patterns

    But the fact is that in this place was the code that we changed. But when updating the docker, the code did not change.

    Therefore, if you are checking someone else's code and for some reason you are not updating, check this.

    And so in general this approach works:

    docker-compose down

    docker-compose build

    docker-compose up -d

    0 讨论(0)
  • 2021-01-30 08:32

    To get the latest images use docker-compose build --pull

    I use below command which is really 3 in 1

    docker-compose down && docker-compose build --pull && docker-compose up -d

    This command will stop the services, pulls the latest image and then starts the services.

    0 讨论(0)
  • 2021-01-30 08:38

    To close this question, what seemed to have worked is indeed running

    docker-compose stop
    docker-compose rm -f
    docker-compose -f docker-compose.yml up -d
    

    I.e. remove the containers before running up again.

    What one needs to keep in mind when doing it like this is that data volume containers are removed as well if you just run rm -f. In order to prevent that I specify explicitly each container to remove:

    docker-compose rm -f application nginx php
    

    As I said in my question, I don't know if this is the correct process. But this seems to work for our use case, so until we find a better solution we'll roll with this one.

    0 讨论(0)
  • 2021-01-30 08:38

    The docker-compose documentation for the 'up' command clearly states that it updates the container should the image be changed since the last 'up' was performed:

    If there are existing containers for a service, and the service’s configuration or image was changed after the container’s creation, docker-compose up picks up the changes by stopping and recreating the containers (preserving mounted volumes).

    So by using 'stop' followed by 'pull' and then 'up' this should therefore avoid issues of lost volumes for the running containers, except of course, for containers whose images have been updated.

    I am currently experimenting with this process and will include my results in this comment shortly.

    0 讨论(0)
提交回复
热议问题