Managing application images

Docker Compose can manage Docker images, as well as containers. In the Compose file, you can include attributes that tell Docker Compose how to build your images. You can specify the location of the build context to send to the Docker service, which is the root folder for all your application content—and the location of the Dockerfile.

The context path is relative to the location of the Compose file, and the Dockerfile path is relative to the context. This is very useful for complex source trees, such as the demo source for this book, where the context for each image is in a different folder. In the ch06-docker-compose-build folder, I have a full Compose file with application specification, complete with the build attributes specified.

This is how the build details are specified for my images:

nerd-dinner-db:
image: dockeronwindows/ch06-nerd-dinner-db:2e
build:
context: ../ch06-nerd-dinner-db
dockerfile:
./Dockerfile
...
nerd-dinner-save-handler:
image: dockeronwindows/ch05-nerd-dinner-save-handler:2e
build:
context: ../../ch05
dockerfile: ./ch05-nerd-dinner-save-handler/Dockerfile

When you run docker-compose build, any services that have the build attribute specified will be built and tagged with the name in the image attribute. The build process uses the normal Docker API, so the image layer cache is still used, and only changed layers are rebuilt. Adding build details to your Compose file is a very efficient way of building all your application images, and it's also a central place to capture how the images are built.

One other useful feature of Docker Compose is the ability to manage whole groups of images. The Compose file for this chapter uses images that are all publicly available on Docker Hub, so you can run the full application with docker-compose up—but the first time you run it, all the images will be downloaded, which is going to take a while. You can preload images before you use them with docker-compose pull, which will pull all the images:

> docker-compose pull
Pulling message-queue ... done
Pulling elasticsearch ... done
Pulling reverse-proxy ... done
Pulling kibana ... done
Pulling nerd-dinner-db ... done
Pulling nerd-dinner-save-handler ... done
Pulling nerd-dinner-index-handler ... done
Pulling nerd-dinner-api ... done
Pulling nerd-dinner-homepage ... done
Pulling nerd-dinner-web ... done

Similarly, you can use docker-compose push to upload images to remote repositories. For both commands, Docker Compose uses the authenticated user from the most recent docker login command. If your Compose file contains images you don't have access to push, those pushes will fail. For any repositories you are authorized to write to, whether in Docker Hub or a private registry, these images will be pushed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.93.64