14

I would like to take my application stack, consisting of 3 docker images and managed by docker-compose, and move it in its entirety from my development machine onto a production machine. I know of a few ways to do this with straight up docker:

  • Push the images to the registry and pull them back out from production
  • docker save from development and then docker load on production
  • rebuild the images on production (would rather keep dependencies down on production, so not a good option.)

I'm currently leaning towards doing docker save and then docker load, but am wondering if there's a way to do this with the whole set of containers that docker-compose manages?

Thanks in advance

Josh
  • 183
  • 1
  • 9
  • Images are pushed to a registry, containers are meant to be disposable. Did you make changes to the containers that you'd like to keep around? If so, those changes should be baked into the base images. – Kevan Ahlquist Jan 26 '16 at 22:20
  • @KevanAhlquist - you are correct, I am confused about the terminology. I'll update the question to reflect that. – Josh Jan 27 '16 at 15:19

1 Answers1

9

There is no functionality in Compose to save the images built in a Compose file, it's the job of the docker client (as you stated with docker save and docker load). Fortunately it's straightforward with bash:

images=(web cache db)
for image in images
do
    docker save ${image} > ${image}.tar
    scp ${image}.tar $yourhost:
    ssh $yourhost docker load ${image}.tar
done

The remote registry option is perhaps a more "production grade" approach. Moving a bunch of images around is likely to be pretty slow, but YMMV.

Ben Whaley
  • 32,811
  • 7
  • 87
  • 85
  • 2
    I'm not sure that works because it doesn't save the images for each step of the DockerFile. For instance, if you save your 3 images and then run a docker rm $(docker ps -a -q) && docker rmi $(docker images -q), and then docker load everything you saved, a "docker-compose build ." will not use the cache for the individual steps. Don't you have to run something like "docker history" to get all the layers and then save each layer? – grayaii Jun 14 '17 at 12:23