Docker Compose
Definition
Docker Compose is a tool that was developed to help define and share multi-container applications.
- Docker Desktop will group running containers in tabs of different applications (same as folder name in which
docker-compose.ymlis located).
resources
- awesome-compose collects great
docker-composefiles for common App setups.
docker compose file
Docker Compose is a tool for defining and running multi-container Docker applications.
-
Define a
docker-compose.ymlfile, e.g.version: "2" services: voting-app: build: ./voting-app/. volumes: - ./voting-app:/app ports: - "5000:80" links: - redis networks: - front-tier - back-tier result-app: build: ./result-app/. volumes: - ./result-app:/app ports: - "5001:80" links: - db networks: - front-tier - back-tier worker: image: manomarks/worker links: - db - redis networks: - back-tier redis: image: redis:alpine ports: ["6379"] networks: - back-tier db: image: postgres:9.4 volumes: - "db-data:/var/lib/postgresql/data" networks: - back-tier volumes: db-data: networks: front-tier: back-tier: -
Launch your app. In the same directory as your
.ymlfile:docker-compose up -d
New: compose is now a built-in docker command
docker compose up -dlinks
With
links:
- dbthe container will wait for the db container to finish building
profiles
- Add certain containers in your
docker-compose.ymlfile to aprofile. - When running
docker-composethat container will only be launched if--profile {profile_name}is added.
e.g. docker-compose --profile my_profile up will only run the container which has the following attribute:
profiles:
- my_profileTroubleshooting
If docker-compose up throws errors, some cached files might cause trouble. Run:
docker-compose buildThis runs the Dockerfile for sure even if stuff is cached in the case of docker-compose up.
Live Server vs. Development docker-compose.yml file
your docker-compose file:
Live
services:
my_app:
image: my_dockerhub_account/my_app
...Dev on localhost
services:
my_app:
build: .
volumes:
- ./my-app:/app
...Discuss on Twitter ● Improve this article: Edit on GitHub