Skip to content

docker compose

Created: 2019-01-04 11:39:04 -0800 Modified: 2019-01-21 09:44:15 -0800

  • 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 any depends_on chains, e.g. if webServer depends on db, you still only need to type webServer.
    • Note that if you do only specify webServer in the example above and then send ⌃C to Docker, it will not shut down db. You have to run docker compose down to shut it down properly (or just specify docker compose up webServer db initially)
  • 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”.
services:
webServer:
image: foo/webserver:latest
networks:
- overlay
ports:
- '8080:8080'
somethingThatUsesTheWebServer:
image: foo/bar:latest
networks:
- overlay
environment:
OVERSEER_REST_URL: http://webServer:8080
networks:
? overlay

With 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 named delete_me_env and it didn’t work.
  • 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).
version: '2.2'
services:
game-server:
image: foo/bar:1.2.3
cpus: 0.5

Limiting which cores a service can run on (“cpuset”)

Section titled Limiting which cores a service can run on (“cpuset”)
version: '2.2'
services:
foo:
image: foo:latest
cpuset: '0,1'
bar:
image: bar:latest
cpuset: '2'