Docker Compose basics and commands

What is Docker Compose?

A tool for Docker applications that define and run multiple containers. Set up application services using YAML files. Mainly used in the following cases.

--When the $ docker run command gets longer --When starting multiple containers at once

Example of how to write a YAML file

An example YAML file when the docker command is as follows.

$ docker build .
$ docker run -it -v ~/Desktop/myapp:/myapp -p 3000:3000 <image> bash

The YAML file is as follows.

version: '3'

services:
  web:
    build: .
    ports:
      - '3000:3000'
    volumes:
      - '.:/myapp'
    tty: true
    stdin_open: true

Web naming is arbitrary, but web or app is often used. The correspondence between docker commands (run option) and YAML files is as follows.

docker command YAML file
build build:
-i stdin_open: true
-t tty: true
-v volumes:
-p ports:

Docker Compose command

The correspondence with the Docker command is as follows.

command Dockercommand
docker-compose build docker build
docker-compose up docker run
docker-compose ps docker ps
docker-compose exec <sevice> <command> docker exec <container> <command>
docker-compose up --build build and run
docker-compose down stop and rm

Reference: Official document

English Japanese

Recommended Posts

Docker Compose basics and commands
Docker terms and commands
Docker basics
Docker basic commands
Introduction of Docker Hub and commands Self-learning ①
Docker installation and initialization
Docker Frequently used commands
Docker settings and this and that
Overview of Docker and containers
Docker monitoring-explaining the basics of basics-
Latest docker installation (Ubuntu 20.04 and Ubuntu 20.10)
Understand the basics of docker
Installing and building Docker (memo)
Basics of conditional branching and return
Node.js environment construction with Docker Compose
Docker network related research & configuration commands
Use Docker Compose on Windows 10 Home
Hello World with Docker and C
[Ruby basics] split method and to_s method
Build Rails environment with Docker Compose
WordPress with Docker Compose on CentOS 8
Summary of frequently used Docker commands
2. Create Docker image and register Registry
Microservices With Docker and Cloud Performance
Challenge to install WSL2 and docker
Docker related commands (notes for yourself)
Introduction to Docker (1) Frequently used commands
About Docker, disguise server and container
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
[Copy and paste] Build a Laravel development environment with Docker Compose Participation