Docker Compose Config

Diving into docker compose files (docker-compose.yml) there is a lot of keywords used. Some are obvious, others not. Here’s a little cheat sheet, not at all total coverage but hopefully a few nuggets to get started.

docker-compose file


Build points to your Dockerfile. If it’s named Dockerfile and resides in the same directory as your docker-compose.yml you can specify it with a dot (.) otherwise you can give it a path.

You can only use build OR image (se below) not both.


Names an image, local or remote (if its not local docker will try to pull it down). Could for example be redis, ubuntu, mongodb or something else.


This is used to set up relationships (links) between docker containers in your compose environment.

It’s also possible to set up aliases using the links.

- redis:cache


Pretty self-explaining. What ports should be mapped out to the outside world. Follows a :, so if you have a web server on port 80 and want to expose it on port 80 you do a 80:80. If you only give it 80 it will give you a random port for the outside world to use that maps into port 80 on that container.

So this example maps 80 to port 80, and port 8080 to a random port and interval 8000-8030 to 3000-3030.


Is used to mount paths as volumes. Can mount on the host machine or in the container.


Is used to mount volumes from another container or service. So and example could be a web server mounting volumes from a file server.


Specifies a custom name for the container.


Adds environment variables to the container. That in node.js for example can be accessed using process.env.

Next up I’ll look at the docker file.

Lämna ett svar

E-postadressen publiceras inte. Obligatoriska fält är märkta *

Denna webbplats använder Akismet för att minska skräppost. Lär dig hur din kommentardata bearbetas.