docker compose
Created: 2019-01-04 11:39:04 -0800 Modified: 2019-01-21 09:44:15 -0800
Basics
Section titled Basics- If you have several services defined but only want to start a subset of them, you can specify their names after
docker-compose up
, e.g.docker-compose up webServer
. This will automatically follow anydepends_on
chains, e.g. ifwebServer
depends ondb
, you still only need to typewebServer
.- Note that if you do only specify
webServer
in the example above and then send ⌃C to Docker, it will not shut downdb
. You have to rundocker compose down
to shut it down properly (or just specifydocker compose up webServer db
initially)
- Note that if you do only specify
- You can build with
docker-compose build
. This still requires a Dockerfile to build. The image name is pulled from YAML (reference). - You can use the service names as host names if the networks are shared. For example, suppose you have an environment variable called “endpointUrl” that is usually set to something like “http://localhost:8080”.
Specifying environment variables
Section titled Specifying environment variablesWith docker-compose
, there’s only the host OS’s environment variables and .env
files.
- See this table for precedence rules
- Any
.env
files seemingly have to start with.env
in their filename. I tried file nameddelete_me_env
and it didn’t work.
Limiting a container’s resources (reference)
Section titled Limiting a container’s resources (reference)- If you’re using Docker swarm, you can specify deploy → resources → limits → cpu and memory.
- If you’re using docker-compose, then you have to use file format version 2 (reference) (actually, version 2.2 if you want to just use
cpus
).