Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Docker Compose Compose vs Kubernetes
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-docker-compose-compose-vs-kubernetes

Docker Docker Docker Compose Compose vs Kubernetes

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~2 min read

1. Core Command / Concept

Compose vs Kubernetes allows you to manage and orchestrate multiple containers across multiple hosts. docker-compose up

2. Step-by-Step

  1. Create a new directory for your project and navigate into it: mkdir myproject && cd myproject
  2. Create a new file named docker-compose.yml and add the following content: version: '3' services: web: build: . ports: - "80:80"
  3. Run docker-compose up to start the container: docker-compose up
  4. Check if the container is running: docker ps
  5. ⚠️ Stop the container: docker-compose stop
  6. Remove the container: docker-compose rm
  7. Remove the network: docker-compose down

3. Real Commands with Examples


Example 1: Build and Run a Container

Purpose: Build a Docker image from a Dockerfile and run it.
Command: docker-compose up --build Flags: --build flag tells Docker to rebuild the image if it already exists.

Example 2: Scale a Service

Purpose: Scale a service to run 3 instances.
Command: docker-compose up -d --scale web=3 Flags: -d flag runs the container in detached mode, --scale flag scales the service.

Example 3: Link Containers

Purpose: Link a database container to a web container.
Command: docker-compose up -d --link db:database Flags: --link flag links the database container to the web container.

4. Common Errors


Error 1: Image Not Found

Error message: Error: No such image: myimage Why it happens: The image does not exist in the local Docker registry.
Fix: docker pull myimage

Error 2: Port Already in Use

Error message: Error: Port 80 is already in use Why it happens: Another process is using port 80.
Fix: docker-compose up -p 8080

Error 3: Service Not Found

Error message: Error: Service 'web' not found Why it happens: The service does not exist in the docker-compose.yml file.
Fix: docker-compose up -f docker-compose.yml

5. Quick Checks


Scenario 1: Check if a Container is Running

Situation: You want to check if a container is running.
Command: docker ps Correct response: The container ID and name should be listed.

Scenario 2: Check if a Service is Running

Situation: You want to check if a service is running.
Command: docker-compose ps Correct response: The service name and status should be listed.

Scenario 3: Check if a Network is Created

Situation: You want to check if a network is created.
Command: docker network ls Correct response: The network name should be listed.

6. Last-Minute Reference

  • docker-compose up builds and starts containers
  • docker-compose down stops and removes containers
  • docker-compose rm removes containers
  • docker-compose ps lists running services
  • docker-compose logs displays container logs
  • docker-compose exec runs a command in a running container
  • docker-compose config displays the configuration
  • docker-compose build builds Docker images
  • docker-compose push pushes images to a registry
  • ⚠️ docker-compose up -d runs containers in detached mode


ADVERTISEMENT