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

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.

image

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.

links

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

ports

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.

volumes

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

volumes_from

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

container_name

Specifies a custom name for the container.

environment

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.

Kommentera

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