Computer Science/DevOps

overview of docker compose 🐳 | 도커 컴포즈 공식 문서 | 개념편

토마토. 2021. 8. 30. 13:15

 

참고 - https://docs.docker.com/compose/

 

Overview of Docker Compose

 

docs.docker.com

 

참고 2 - Orientation and setup | Docker Documentation

도커 도큐먼트도 곁들이기 :)

 

🐳 overview of docker compose 🐳

 

컴포즈는 여러 개의 도커 컨테이너를 돌릴 때 사용한다.

 

컴포드가 깔려있으면, 

YAML 파일로 전체 application의 서비스를 구성해서

각각을 실행시키는 것이 아니라

하나의 명령어로 여러 컨테이너로 구성된 서비스를 시작할 수 있다. 

 

$ docker-compose up

얘 하나면 끝!

 

컴포즈의 기능을 더 알아보려면

다음 링크에 들어가면 된다.

the list of features.

 

그리고 컴포즈는 다양한 환경에서 작동한다. 

production, staging, development, testing, as well as CI workflows.

 

* CI continuous integration :  

개발자들이 애플리케이션에 적용한 변경 사항이 버그 테스트를 거쳐 리포지토리(예: GitHub 또는 컨테이너 레지스트리)에 자동으로 업로드되는 것

참고 - CI/CD(지속적 통합/지속적 제공): 개념, 방법, 장점, 구현 과정 (redhat.com)

 

자세한 내용은 링크 참고!

Common Use Cases.

 

 

보통 컴포즈 사용은 3단계 구성된다고 한다.

 

step 1.

(service마다 dockerfile에 application의 환경 정의하기)(재사용 가능함)

 

step 2. docker-compose.yml 파일에각 서비스 정의해서독립된 환경에서 동작하도록 하기!

 

step 3. docker compose up 명령어로docker-compose를 시작하고전체 application을 한 번에 돌리기!

 

 

 

도커즈 파일은 다음과 같이 생겼다.

docker-compose.yml

version: "3.9"  # optional since v1.27.0
services:
  web:
    build: .
    ports:
      - "5000:5000"
    volumes:
      - .:/code
      - logvolume01:/var/log
    links:
      - redis
  redis:
    image: redis
volumes:
  logvolume01: {}

 

자세한 내용은 링크로 확인 바람!

Compose file reference.

 

 

application의 lifecycle을 관리하기 위한

여러 명령어가 있다. 

 

 

  • Start, stop, and rebuild services
  • View the status of running services
  • Stream the log output of running services
  • Run a one-off command on a service (일회성)

 

 

🐳 compose documentation 🐳

 

 

🐳 Features 🐳

컴포즈의 특징(장점)

 

 

🐳 features 1 🐳

하나의 기기에서 다수의 독립된 환경을 사용할 수 있다.

Multiple isolated environments on a single host 

 

 

Compose uses a project name

to isolate environments from each other.

 

You can make use of this project name

in several different contexts:

 

 

  • on a dev host, to create multiple copies of a single environment, such as when you want to run a stable copy for each feature branch of a project
  • on a CI server, to keep builds from interfering with each other, you can set the project name to a unique build number
  • on a shared host or dev host, to prevent different projects, which may use the same service names, from interfering with each other

 

The default project name

is

the basename of the project directory.

 

You can set a custom project name

by using the -p command line option 

or the COMPOSE_PROJECT_NAME environment variable.

 

The default project directory

is

the base directory of the Compose file.

 

A custom value for it

can be defined

with the --project-directory command line option.

 

🐳 feature 2 🐳

Preserve volume data when containers are created

큰 규모의 데이터도 문제 X

 

Compose

preserves

all volumes used by your services.

 

When docker-compose up runs,

if it finds any containers from previous runs,

it copies the volumes from the old container to the new container.

 

This process

ensures

that any data you’ve created in volumes isn’t lost.

 

If you use docker-compose on a Windows machine,

see Environment variables 

and adjust the necessary environment variables

for your specific needs.

 

 

🐳 feature 3🐳

Only recreate containers that have changed

바뀐 부분만 감지해서 컨테이너 생성

 

Compose

caches

the configuration used to create a container.

 

When you restart a service

that has not changed,

Compose re-uses the existing containers.

 

Re-using containers

means

that you can make changes

to your environment very quickly.

 

 

🐳 feature 4 🐳

Variables and moving a composition between environments

 

Compose

supports

variables in the Compose file.

 

You can use these variables

to customize your composition

for different environments, or different users.

 

See Variable substitution for more details.

 

You can extend

a Compose file

using the extends field or by creating multiple Compose files.

 

See extends for more details.

 

🐳 Common use cases 🐳

Compose can be used in many different ways.

Some common use cases are outlined below.

 

🐳 1 🐳

Development environments

 

When you’re developing software,

the ability

to run an application

in an isolated environment

and interact with it

is crucial.

 

The Compose command line tool

can be used

to create the environment and interact with it.

 

The Compose file 

provides a way

to document and configure(구성)

all of the application’s service dependencies

(databases, queues, caches, web service APIs, etc).

 

Using the Compose command line tool

you can create and start one or more containers

for each dependency with a single command (docker-compose up).

 

Together,

these features provide a convenient way

for developers to get started on a project.

 

Compose can reduce

a multi-page “developer getting started guide”

to a single machine readable Compose file and a few commands

 

 

🐳 2 🐳

Automated testing environments

 

An important part of any Continuous Deployment or Continuous Integration process

is the automated test suite.

 

* CD Continuous Deployment / CI Continuous Integration *

CI/CD(지속적 통합/지속적 제공): 개념, 방법, 장점, 구현 과정 (redhat.com)

 

Continuous Integration : "CI"는 개발자를 위한 자동화 프로세스인 지속적인 통합(Continuous Integration)을 의미합니다. 지속적인 제공이란 개발자들이 애플리케이션에 적용한 변경 사항이 버그 테스트를 거쳐 리포지토리(예: GitHub 또는 컨테이너 레지스트리)에 자동으로 업로드되는 것을 뜻하며...

 

Continuous Deployment : 지속적인 배포(또 다른 의미의 "CD": Continuous Deployment)란 개발자의 변경 사항을 리포지토리에서 고객이 사용 가능한 프로덕션 환경까지 자동으로 릴리스하는 것을 의미합니다. 이는 애플리케이션 제공 속도를 저해하는 수동 프로세스로 인한 운영팀의 프로세스 과부하 문제를 해결합니다. 

 

Automated end-to-end testing

requires an environment

in which to run tests.

 

Compose provides a convenient way

to create and destroy isolated testing environments

for your test suite.

 

By defining the full environment in a Compose file,

you can create and destroy these environments

in just a few commands:

 

 

🐳 3 🐳

Single host deployments

 

Compose has traditionally been focused on development and testing workflows,

but with each release

we’re making progress on more production-oriented features.

 

For details on using production-oriented features,

see compose in production in this documentation.

 

* production-oriented ?

 

🐳 Release notes 🐳

To see a detailed list of changes for past and current releases of Docker Compose,

refer to the CHANGELOG.

 

🐳 Getting help 🐳

Docker Compose is under active development.

If you need help, would like to contribute, or simply want to talk about the project with like-minded individuals,

we have a number of open channels for communication.

 

    • To report bugs or file feature requests: use the issue tracker on Github.
    • To talk about the project with people in real time: join the #docker-compose channel on the Docker Community Slack.
    • To contribute code or documentation changes: submit a pull request on Github.

 

* 사용 예제와 섞은 참고 사이트 *

 

docker-compose 를 이용한 개발환경 구축하기 ( feat. vagrant ) :: ggoals 의 개발 Note. (tistory.com)

 

docker-compose 를 이용한 개발환경 구축하기 ( feat. vagrant )

이런 경험 다들 있으시죠?? 처음 시작은 ... New 구성원이 팀에 배치를 받아 해당 구성원의 PC 에 프로젝트 개발환경을 셋팅해줘야 되는 경우 그런데 하필 운이 없게도.. 팀이 완전히 셋팅되기 전

ggoals.tistory.com

1~5단계까지 굿