How to Update Existing Images With Docker Compose

How to Update Existing Images With Docker Compose

Docker containers are designed to be disposable and easily replaced. Therefore, we should pull the updated image and launch a fresh instance of the container whenever the base image for a container receives an update.

This article will discuss how to update existing images with docker-compose.

Update Existing Images With Docker Compose

Ensure all photos have been downloaded before updating the containers with the new images to minimize the time spent in an intermediate state or being in the middle in the event that an image download fails.

  1. Update the latest image using the following snippet.

    docker-compose pull
    
  2. Restart the containers using the command below. The snippet above will only recreate changed containers.

    We can also append the --force-recreate on this command; however, this will only recreate containers that are not changed.

    docker-compose up -d --remove-orphans
    
  3. As an optional step, remove any obsolete images.

    docker image prune
    

    For the last step, we don’t need the use of the -f or --force-recreate parameters, as this could lead to destructive side effects on our images.

Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn

Related Article - Docker Compose