Docker Compose
You can network together multiple containers to create a single service using the docker compose utility. Docker composition is defined using a docker-compose.yml
file.
You can point a docker compose service at a Dockerfile
on the local file system to build
from by using the build
command and a path to the directory containing the target Dockerfile
.
# docker-compose.yml
services:
my_service:
build: ./path/to/directory/
You can also point to a local and custom named Dockerfile
s by specifying a context
directory and a custom Dockerfile
name.
# docker-compose.yml
services:
my_service:
build:
context: ./path/to/directory
dockerfile: Dockerfile
You can build all images associated with a docker service composition by using the build
command. This will build all Dockerfile
s that are referenced in the docker-compose.yaml
file. It’s important to note that you must re-run this command before starting your service each time a Dockerfile
changes.
$ docker compose build
You can start a service composed of docker containers (and spin up / network all the associated containers) using the up
command. This command does NOT rebuild docker images when run.
$ docker compose up
You can keep a container that is initialised using docker compose running by using the tail
command as an initial execution task for the container.
my_service:
image: ubuntu
command: tail -F anything