By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Docker Compose allows you to define and run multi-container applications with a single command. docker-compose up
mkdir myproject && cd myproject
docker-compose.yml
version: '3' services: web: build: . ports: - "8080:80"
docker-compose up
docker ps
docker-compose stop
docker-compose rm
docker network rm myproject_default
docker volume rm myproject_default
Purpose: Run a simple web server using the official Python image.Command: docker-compose up -d --build Flags: - -d runs the containers in detached mode.- --build builds the Docker image from the current directory.
docker-compose up -d --build
-d
--build
Purpose: Run a PostgreSQL database and a web server using the official Python image.Command: docker-compose up -d Flags: - -d runs the containers in detached mode.
docker-compose up -d
Purpose: Run a web server using the official Python image with environment variables.Command: docker-compose up -d --env-file .env Flags: - --env-file loads environment variables from a file.
docker-compose up -d --env-file .env
--env-file
Error message: ERROR: Service 'web' uses an image, but 'docker-compose config' indicates support for Docker Compose files. Why it happens: The image is not defined in the docker-compose.yml file.One-line fix: docker-compose config to check the configuration.
ERROR: Service 'web' uses an image, but 'docker-compose config' indicates support for Docker Compose files.
docker-compose config
Error message: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:8080: bind: address already in use Why it happens: The port is already in use by another process.One-line fix: docker-compose stop to stop the container.
Error response from daemon: Ports are not available: listen tcp 0.0.0.0:8080: bind: address already in use
Error message: ERROR: The container name "/myproject_web_1" is already in use by container "/myproject_web_1". Why it happens: The volume is already in use by another container.One-line fix: docker-compose rm to remove the container.
ERROR: The container name "/myproject_web_1" is already in use by container "/myproject_web_1".
Situation: You want to check if a container is running.Command: docker ps What a correct response looks like: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Situation: You want to check the logs of a container.Command: docker-compose logs -f What a correct response looks like: The logs of the container.
docker-compose logs -f
Situation: You want to check the status of a service.Command: docker-compose ps What a correct response looks like: The status of the service.
docker-compose ps
docker-compose down
docker-compose restart
docker-compose logs
docker-compose exec
docker-compose run
docker-compose rm -f
docker-compose down -v
docker-compose stop --time=1
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.