ubuntu20.04.6에Docker Compose설치 사용하기

linux Linux

Docker Compose는 YAML 파일 정의를 사용하여 다중 컨테이너 애플리케이션 환경을 실행할 수 있는 도구입니다. ubuntu20.04.6에 설치하는 방법을 소개합니다.

Docker Compose를 사용하기위해서는 [ubuntu20.04.6에서 Docker설치 사용하기]를 먼저 실행해야합니다.

Docker Compose설치하기

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

PostgreSQL + PgAdmin2설치 파일 만들기

mkdir ~/postgre+pgadmin/data
cd ~/postgre+pgadmin
vi docker-compose.yml
version: '3.5'

services:
  postgres:
    container_name: postgres_container
    image: postgres
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "postgres"
    volumes:
      - /home/ubuntu/postgre+pgadmin/data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - postgres
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-mail@mail.com}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-password}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    volumes:
      - pgadmin:/var/lib/pgadmin
    ports:
      - "${PGADMIN_PORT:-82}:80"
    networks:
      - postgres
    restart: unless-stopped

networks:
  postgres:
    driver: bridge

volumes:
  postgres:
  pgadmin:

Docker Compose 실행

docker-compose up -d
Pulling postgres (postgres:)...
latest: Pulling from library/postgres
a803e7c4b030: Pull complete
... 중간생략 ...
Digest: sha256:f1aaf6f8be5552bef66c5580efbd2942c37d7277cd0416ef4939fa34bf0baf31
Status: Downloaded newer image for postgres:latest
Pulling pgadmin (dpage/pgadmin4:)...
latest: Pulling from dpage/pgadmin4
7264a8db6415: Pull complete
... 중간생략 ...
Digest: sha256:dafe1099f93655a5ee3de90882d79dc92c74553b8884f816bb26777f90da4960
Status: Downloaded newer image for dpage/pgadmin4:latest
Creating pgadmin_container   ... done
Creating posetgres_container ... done
docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED         STATUS         PORTS                                        NAMES
47092a39f5d4   postgres         "docker-entrypoint.s…"   2 minutes ago   Up 2 minutes   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp    postgres_container
2db5df95c138   dpage/pgadmin4   "/entrypoint.sh"         2 minutes ago   Up 2 minutes   443/tcp, 0.0.0.0:82->80/tcp, :::82->80/tcp   pgadmin_container

Docker Compose 컨테이너 정지/삭제

docker-compose stop
Stopping pgadmin_container   ... done
Stopping posetgres_container ... done
docker ps
       Name                      Command              State    Ports
--------------------------------------------------------------------
pgadmin_container     /entrypoint.sh                  Exit 0
posetgres_container   docker-entrypoint.sh postgres   Exit 0
docker-compose rm
Going to remove pgadmin_container, posetgres_container
Are you sure? [yN] y
Removing pgadmin_container   ... done
Removing posetgres_container ... done
docker ps
Name   Command   State   Ports
------------------------------

docker images삭제

docker images
REPOSITORY       TAG       IMAGE ID       CREATED        SIZE

dpage/pgadmin4   latest    ce8ae42da4a0   2 weeks ago    545MB
postgres         latest    2d74f8a2591c   3 weeks ago    417MB
docker rmi postgres dpage/pgadmin4
Untagged: postgres:latest
Untagged: postgres@sha256:f1aaf6f8be5552bef66c5580efbd2942c37d7277cd0416ef4939fa34bf0baf31
Deleted: sha256:2d74f8a2591ca34f2ea0565e385325570dd618e2d07372a8bb0ba97bddd19c93
... 중간생략 ...
Untagged: dpage/pgadmin4:latest
Untagged: dpage/pgadmin4@sha256:dafe1099f93655a5ee3de90882d79dc92c74553b8884f816bb26777f90da4960
Deleted: sha256:ce8ae42da4a0604ad9a44c3e8cdfdcb61199407b5794e2791020878241969141
... 중간생략 ...
제목과 URL을 복사했습니다