This file is documenting best practices when it comes to using docker-compose files.
- Each service should be sorted in alpabetical order
- Each variable in environment should be sorted in alphabetical order
- Each service must have a
container_name
and it must be the same as the service name.
version: '3'
services:
api_gateway:
container_name: api_gateway
...
- Each service must have the following structure (where applicable)
service_name:
container_name:
build: *OPTIONAL - if building images locally from a Dockerfile.*
image: *OPTIONAL - if pulling images from dockerhub repo.*
restart: *OPTIONAL - if container needs to continually restart or reconnect on failure.*
volumes:
- local_folder:container_folder
environment:
- container_env_variable=$variable_from_env_file
ports: *OPTIONAL - if container needs to publicly expose ports.*
- $some_port:$some_port
expose: *OPTIONAL - if contianer only needs to expose ports within private network.*
- $some_private_port
networks:
- network_name
Allows different docker containers to communicate via the localhost.
Important to note, this means each docker container that exposes a port, has each others ports exposed inside of the containers.
At the moment can't interact from an external to the exposed ports.
ports:
# Only internally exposed.
- $P2P_PORT:$P2P_PORT
- $RPC_PORT:$RPC_PORT
network_mode: host
$ docker network create --subnet=172.0.0.0/25 local_dev
$ docker network inspect local_dev