Debug School

rakesh kumar
rakesh kumar

Posted on

List out checklist of docker Compose command

Docker Compose is a tool for defining and running multi-container Docker applications. Here's a checklist of common Docker Compose commands with detailed examples and expected outputs:

Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application which required NGNIX and MySQL, you could create one file which would start both the containers as a service without the need to start each one separately.

Image description

Image description

1. Create a Docker Compose File:
Create a docker-compose.yml file defining your services, networks, and volumes.

Example (docker-compose.yml):

version: '3'
services:
  web:
    image: nginx:alpine
    ports:
      - "8080:80"
  db:
    image: postgres:latest
    environment:
      POSTGRES_DB: mydatabase
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
Enter fullscreen mode Exit fullscreen mode

2. Start Services Defined in Compose File:

docker-compose up -d
Expected Output:


Creating network "myproject_default" with the default driver
Creating myproject_web_1 ... done
Creating myproject_db_1  ... done
Enter fullscreen mode Exit fullscreen mode

3. List Running Services:

docker-compose ps
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Image description

4. View Logs of Services:

docker-compose logs
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Image description

5. Stop Services:

docker-compose down
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Image description

6. Build and Start Services:

docker-compose up --build -d
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Building web
Step 1/2 : FROM nginx:alpine
 ---> abcdef123456
...
Successfully built abcdef123456
Creating myproject_web_1 ... done
Creating myproject_db_1  ... done
Enter fullscreen mode Exit fullscreen mode

7. Scale Services:

docker-compose up -d --scale web=3
Enter fullscreen mode Exit fullscreen mode

Expected Output:

Creating network "myproject_default" with the default driver
Creating myproject_db_1  ... done
Creating myproject_web_1 ... done
Creating myproject_web_2 ... done
Creating myproject_web_3 ... done
Enter fullscreen mode Exit fullscreen mode

8. List Docker Compose Version:

docker-compose version
Enter fullscreen mode Exit fullscreen mode

Expected Output:

docker-compose version 1.29.2, build 1110ad01
docker-py version: 5.0.2
CPython version: 3.7.10
Enter fullscreen mode Exit fullscreen mode

9. Pause and Unpause Services:

docker-compose pause
docker-compose unpause
Enter fullscreen mode Exit fullscreen mode

10. Execute Command in a Service Container:

docker-compose exec web ls /usr/share/nginx/html
Enter fullscreen mode Exit fullscreen mode

Expected Output:

index.html
Enter fullscreen mode Exit fullscreen mode

11. Display Compose Configuration:

docker-compose config
Enter fullscreen mode Exit fullscreen mode

Expected Output:

services:
  db:
    environment:
      POSTGRES_DB: mydatabase
      POSTGRES_PASSWORD: mypassword
      POSTGRES_USER: myuser
    image: postgres:latest
    networks:
      myproject_default:
    volumes: null
  web:
    image: nginx:alpine
    networks:
      myproject_default:
        aliases:
          myproject_web_1:web
    ports:
    - 8080:80
    volumes: null
networks:
  myproject_default:
    external: true
version: '3.0'
Enter fullscreen mode Exit fullscreen mode

12. Build and Push Services Images:

docker-compose build
docker-compose push
Enter fullscreen mode Exit fullscreen mode

These Docker Compose commands provide essential functionality for defining, building, and managing multi-container applications. Adjust the examples based on your specific use case and project structure.

Top comments (0)