Docker Compose
Last updated
Last updated
Please read our disclaimer https://docs.ibracorp.io/#disclaimer.
You can find our docker-compose templates here, feel free to contribute!
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features.
Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in Common Use Cases.
Using Compose is basically a three-step process:
Define your app’s environment with a
Dockerfile
so it can be reproduced anywhere.Define the services that make up your app in
docker-compose.yml
so they can be run together in an isolated environment.Run
docker compose up
and the Docker compose command starts and runs your entire app. You can alternatively rundocker-compose up
using the docker-compose binary.
Source: https://docs.docker.com/compose/
Always worth checking the official docs:
Install - https://docs.docker.com/compose/install/
Useful Information - https://docs.docker.com/compose/compose-file/compose-file-v3/
If you followed the commands to install docker here for Ubuntu for example - https://docs.docker.com/engine/install/ubuntu/
You can run the following command to install docker compose v1 (where you have to run the command with docker-compose up -d
)
Or the following command for v2 (where you have to run the command with docker compose up -d
)
Docker compose can be run with variable set in an .env
file. If this file is in the same directory as the compose file, it will pick this up automatically.
PLEASE NOTE
With these examples, we have labels for Traefik. if you do not use Traefik, you can simply remove the whole labels section.
An example of a docker-compose.yml
file:
TIP
The first value under ports is always the host.
For example with ports:
This will bind the container port 9091
to the hosts port 9080
For example with volumes:
This will bind the container folder /config
to the hosts path /opt/appdata/authelia
Example of a .env
file
Example how you can combine apps you want to run together and rely on each other to run. You can add a “depends_on
” variable which will not run the container until the others are already running.
You can also separate services on their own secure network and only give access to the apps that require it (example below has Redis and MariaDB on a secure, separated network).
TIP
As you can see above, you can add a container to multiple networks by using the follwing format:
Just note that these are both also defined at the bottom of the compose file:
If all the containers in the compose file are going to be on the same network, you can define a network as default for all containers at the bottom of the file. This means you then do not have to define the "networks:" variable on each container.
Linked .env
file example
TIP
If you would like to bind a folder from the host as read-only, you can do this with the following addition to the volume paths "ro":
If you would like to bind a folder from the host as read-write, you can do this with the following addition to the volume paths "rw":
.env
file to match
TIP
If you would like to add multiple port mappings from the container to the host, you can add them all under the ports:
section.
You can also define the protocal used on each port if required with "/tcp
" or "/udp
".
.env
file to match
A trick you can do with the .env file is you can just create one file, with all your values, then hardlink it to each directory where your docker compose files are. This means you only have to add the variables once, to one file, and if you change it, it changes everywhere. You can hardlink the global .env file with the following command:
Then simply run the docker compose run command to start the container (remember to run these commands from within the folder where the compose file is):
Pulling the latest version of an app is easy, simply pull the latest image and then restart the app (remember to run these commands from within the folder where the compose file is):
Our Discord community our Community Leaders oldcrazyeye, DiscDuck and Sycotix for their input and documentation.
Please support the developers and creators involved in this work to help show them some love. ❤️
We hope you enjoyed this guide. It was conceptualized, written, and implemented by our Community Leader Hawks.
Our work sometimes takes months to research and develop. If you want to help support us please consider:
Liking and Subscribing to our Youtube channel
Joining our Discord server
Becoming a paid member on our IBRACORP website
Donating via Paypal