Tag Archives: 도커 Postgres

[Setting | Docker] PostgreSQL설치

도커에 PostgreSQL을 설치하는 방법을 정리한다.


작성일 : 2022-06-07

1> 최신 안정화 릴리즈 확인

PostgreSQL 링크

DockerHub > Postgres 링크


2> 컨테이너 설치 및 실행

# 마운트 폴더 생성
sudo mkdir /home/opendocs/postgres
sudo mkdir /home/opendocs/postgres/data

# 네트워크 확인 & opdnet IP 대역확인
sudo docker network ls
# - 없을 경우 생성
sudo docker network create --gateway 172.20.0.1 --subnet 172.20.0.0/21 opdnet
# - 네트워크 확인
sudo docker inspect opdnet
# ------------------------------------------
# IPAM > Config > Gateway와 같은대역 IP 지정해야함
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
# Containers에 사용중인 IP는 중복되지 않아야함
        "Containers": {
            "d4c422b0ceb65ab5f45e2efe2c7da3137b7d66a985f3f222b1b974763529ea7c": {
                "Name": "sample",
                "EndpointID": "e0dc778cf7fe452b45c5bec1737050395c553d764de75f3a88aef565fe00166d",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            }
        },
# ------------------------------------------

# 컨테이너 설치 및 실행 (고정IP지정)
sudo docker run --detach \
  --network opdnet --ip 172.20.0.104 \
  --name postgres \
  --volume /home/opendocs/postgres/data:/var/lib/postgresql/data \
  -p 5432:5432 \
  -e POSTGRES_PASSWORD=qwer1234 \
  postgres:14.3

3> DB 접속 확인

DBeaver 툴을 통해 접속여부확인