Search code examples
dockerdocker-composedevelopment-environment

Quick docker container refresh workflow


This is probably a duplicate, but all answers that I saw didn't work for me.

I'm using docker (17.06.2-ce), docker-compose (1.16.1).

I have an image of solr which I use for development and testing purposes (and on CI too). When making changes to the image I need to rebuild the image and recreate containers, so that the containers use the latest possible image, which, in turn, takes the latest possible code from the local repo.

I've created my own image which is based on official solr-docker image. The repo is a folder with additional steps that I'm applying to the image, such as copying files and making changes to existing configs using sed.

I'm working in the repo and have the containers running in the background.

When I need to refresh the containers, I usually do these commands

sudo docker-compose stop sudo docker rm $(sudo docker ps -a -q) sudo docker rmi $(sudo docker images -q) sudo docker-compose up

The above 4 commands is the only way it works for me. All other approaches that I've tried din't rebuild the images and didn't create the containers based off the new, rebuilt images. In other words, the code in the image would be stale.

Questions:

  1. Is it possible to refresh the image + rebuild the container using fewer commands?
  2. Every time I'm running above 4 commands, docker would download ~500MB of dependencies. Is it possible to not to download them and just rebuild the image using updated local code and existing cached dependencies?

Solution

  • I usually do docker-compose rm && docker-compose build && docker-compose up for recreating docker containers: it won't download 500mb.