728x90
반응형
docker-compose를 사용해서 postgresql 을 설치 진행 과 간단한 테스트 방법에 대해 소개하도록 하겠습니다.
PostgreSql compose 파일
version: '3.6'
services:
postgres:
container_name: postgres
image: postgres:14
restart: unless-stopped
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- TZ=Asia/Seoul
volumes:
- ./data:/var/lib/postgresql/data
ports:
- "5432:5432"
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
restart: unless-stopped
ports:
- "5555:80"
volumes:
- ./pgadmin:/var/lib/pgadmin
environment:
- PGADMIN_DEFAULT_EMAIL=example@pgadmin.com
- PGADMIN_DEFAULT_PASSWORD=pgadmin
- TZ=Asia/Seoul
depends_on:
- postgres
PostgreSql 설치
- volumes 디렉토리 생성 및 권한 생성
- pstgressql 과 pgadmin 볼륨과 맵핑할 디렉토리를 생성 한다.
- docker-compose up
mkdir data pgadmin
chmod 777 data pgadmin
docker-compose up -d
[docker_test@centos7:/data1/docker_test/compose/postgresql]$ docker-compose up -d
Pulling postgres (postgis/postgis:latest)...
latest: Pulling from postgis/postgis
f1f26f570256: Pull complete
1c04f8741265: Pull complete
dffc353b86eb: Pull complete
18c4a9e6c414: Pull complete
81f47e7b3852: Pull complete
5e26c947960d: Pull complete
a2c3dc85e8c3: Pull complete
17df73636f01: Pull complete
713535cdf17c: Pull complete
52278a39eea2: Pull complete
4ded87da67f6: Pull complete
05fae4678312: Pull complete
f06b0b681e09: Pull complete
d24b8ffa110e: Pull complete
6456362dbd08: Pull complete
be89676f5f99: Pull complete
Digest: sha256:b7a27a9fdeedc98fc28798d87d67fb17896eed5a4ff6dd300d420de5643455f2
Status: Downloaded newer image for postgis/postgis:latest
Pulling pgadmin (dpage/pgadmin4:)...
latest: Pulling from dpage/pgadmin4
63b65145d645: Pull complete
c2ae92bf3093: Pull complete
0336e7e12a6e: Pull complete
99274f1e74ce: Pull complete
c4dd61273ae2: Pull complete
d300bb5702cd: Pull complete
2d2d362d9413: Pull complete
52558f382e17: Pull complete
cb849b81cd54: Pull complete
ee15939ba2be: Pull complete
8c0ad2b8007b: Pull complete
3bbef2c63b80: Pull complete
e333b65329da: Pull complete
f4b3d9d65332: Pull complete
Digest: sha256:d914d35dc1a5cf86f65c29d44451c05b73e283529e19ffcc25f45f939c579bd9
Status: Downloaded newer image for dpage/pgadmin4:latest
Creating postgres ... done
Creating pgadmin ... done
Pulling postgres (postgis/postgis:latest)...
latest: Pulling from postgis/postgis
f1f26f570256: Pull complete
1c04f8741265: Pull complete
dffc353b86eb: Pull complete
18c4a9e6c414: Pull complete
81f47e7b3852: Pull complete
5e26c947960d: Pull complete
a2c3dc85e8c3: Pull complete
17df73636f01: Pull complete
713535cdf17c: Pull complete
52278a39eea2: Pull complete
4ded87da67f6: Pull complete
05fae4678312: Pull complete
f06b0b681e09: Pull complete
d24b8ffa110e: Pull complete
6456362dbd08: Pull complete
be89676f5f99: Pull complete
Digest: sha256:b7a27a9fdeedc98fc28798d87d67fb17896eed5a4ff6dd300d420de5643455f2
Status: Downloaded newer image for postgis/postgis:latest
Pulling pgadmin (dpage/pgadmin4:)...
latest: Pulling from dpage/pgadmin4
63b65145d645: Pull complete
c2ae92bf3093: Pull complete
0336e7e12a6e: Pull complete
99274f1e74ce: Pull complete
c4dd61273ae2: Pull complete
d300bb5702cd: Pull complete
2d2d362d9413: Pull complete
52558f382e17: Pull complete
cb849b81cd54: Pull complete
ee15939ba2be: Pull complete
8c0ad2b8007b: Pull complete
3bbef2c63b80: Pull complete
e333b65329da: Pull complete
f4b3d9d65332: Pull complete
Digest: sha256:d914d35dc1a5cf86f65c29d44451c05b73e283529e19ffcc25f45f939c579bd9
Status: Downloaded newer image for dpage/pgadmin4:latest
Creating postgres ... done
Creating pgadmin ... done
정상 설치 확인
정상적으로 설치가 완료 되었는지 확인을 위해 docker-compose logs -f [서비스명] 명령으로 설치 관련 에러가 없는지 확인 한다.
docker-compose logs pgadmin
[docker_test@centos7:/data1/docker_test/compose/postgresql]$ docker-compose logs -f postgres pgadmin
Attaching to pgadmin, postgres
pgadmin | NOTE: Configuring authentication for SERVER mode.
pgadmin |
pgadmin | pgAdmin 4 - Application Initialisation
pgadmin | ======================================
pgadmin |
pgadmin | [2023-03-29 09:20:40 +0000] [1] [INFO] Starting gunicorn 20.1.0
pgadmin | [2023-03-29 09:20:40 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
pgadmin | [2023-03-29 09:20:40 +0000] [1] [INFO] Using worker: gthread
pgadmin | [2023-03-29 09:20:40 +0000] [92] [INFO] Booting worker with pid: 92
........................
...........
......
postgres | 2023-03-29 18:26:44.695 KST [69] LOG: checkpoint starting: shutdown immediate
postgres | 2023-03-29 18:26:44.696 KST [69] LOG: checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.002 s; sync files=0, longest=0.000 s, average=0.000 s; distance=0 kB, estimate=8463 kB
postgres | 2023-03-29 18:26:44.700 KST [1] LOG: database system is shut down
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2023-03-29 18:26:58.554 KST [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres | 2023-03-29 18:26:58.554 KST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2023-03-29 18:26:58.554 KST [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2023-03-29 18:26:58.579 KST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2023-03-29 18:26:58.581 KST [29] LOG: database system was shut down at 2023-03-29 18:26:44 KST
postgres | 2023-03-29 18:26:58.584 KST [1] LOG: database system is ready to accept connections
Attaching to pgadmin, postgres
pgadmin | NOTE: Configuring authentication for SERVER mode.
pgadmin |
pgadmin | pgAdmin 4 - Application Initialisation
pgadmin | ======================================
pgadmin |
pgadmin | [2023-03-29 09:20:40 +0000] [1] [INFO] Starting gunicorn 20.1.0
pgadmin | [2023-03-29 09:20:40 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
pgadmin | [2023-03-29 09:20:40 +0000] [1] [INFO] Using worker: gthread
pgadmin | [2023-03-29 09:20:40 +0000] [92] [INFO] Booting worker with pid: 92
........................
...........
......
postgres | 2023-03-29 18:26:44.695 KST [69] LOG: checkpoint starting: shutdown immediate
postgres | 2023-03-29 18:26:44.696 KST [69] LOG: checkpoint complete: wrote 0 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.002 s; sync files=0, longest=0.000 s, average=0.000 s; distance=0 kB, estimate=8463 kB
postgres | 2023-03-29 18:26:44.700 KST [1] LOG: database system is shut down
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2023-03-29 18:26:58.554 KST [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres | 2023-03-29 18:26:58.554 KST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2023-03-29 18:26:58.554 KST [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2023-03-29 18:26:58.579 KST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2023-03-29 18:26:58.581 KST [29] LOG: database system was shut down at 2023-03-29 18:26:44 KST
postgres | 2023-03-29 18:26:58.584 KST [1] LOG: database system is ready to accept connections
- 파일 생성권한이 없다면 아래와 같은 에러가 발생한다.
- pgadmin | ERROR : Failed to create the directory /var/lib/pgadmin/sessions:
[docker_test@centos7:/data1/docker_test/compose/postgresql]$ docker-compose up
Creating network "postgresql_default" with the default driver
Creating postgres ... done
Creating pgadmin ... done
Attaching to postgres, pgadmin
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2023-03-29 18:18:48.407 KST [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres | 2023-03-29 18:18:48.408 KST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2023-03-29 18:18:48.408 KST [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2023-03-29 18:18:48.497 KST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2023-03-29 18:18:48.502 KST [29] LOG: database system was shut down at 2023-03-29 18:18:40 KST
postgres | 2023-03-29 18:18:48.506 KST [1] LOG: database system is ready to accept connections
pgadmin | ERROR : Failed to create the directory /var/lib/pgadmin/sessions:
pgadmin | [Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
pgadmin | HINT : Create the directory /var/lib/pgadmin/sessions, ensure it is writeable by
pgadmin | 'pgadmin', and try again, or, create a config_local.py file
pgadmin | and override the SESSION_DB_PATH setting per
pgadmin | https://www.pgadmin.org/docs/pgadmin4/6.21/config_py.html
Creating network "postgresql_default" with the default driver
Creating postgres ... done
Creating pgadmin ... done
Attaching to postgres, pgadmin
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2023-03-29 18:18:48.407 KST [1] LOG: starting PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
postgres | 2023-03-29 18:18:48.408 KST [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2023-03-29 18:18:48.408 KST [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2023-03-29 18:18:48.497 KST [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2023-03-29 18:18:48.502 KST [29] LOG: database system was shut down at 2023-03-29 18:18:40 KST
postgres | 2023-03-29 18:18:48.506 KST [1] LOG: database system is ready to accept connections
pgadmin | ERROR : Failed to create the directory /var/lib/pgadmin/sessions:
pgadmin | [Errno 13] Permission denied: '/var/lib/pgadmin/sessions'
pgadmin | HINT : Create the directory /var/lib/pgadmin/sessions, ensure it is writeable by
pgadmin | 'pgadmin', and try again, or, create a config_local.py file
pgadmin | and override the SESSION_DB_PATH setting per
pgadmin | https://www.pgadmin.org/docs/pgadmin4/6.21/config_py.html
docker container 상태확인
- docker-compose ps -a 상태 확인 (State -> UP , Port mapping 정보 확인)
- pgadmin 포트는 5555 번으로 설치를 진행 했으며 postgresql 은 5432 포트를 사용 한다.
- 포트 맵핑 정보 확인 => [host port] : [container port]
[docker_test@centos7:/data1/docker_test/compose/postgresql]$ docker-compose ps -a
Name Command State Ports
------------------------------------------------------------------------------------------------
pgadmin /entrypoint.sh Up 443/tcp, 0.0.0.0:5555->80/tcp,:::5555->80/tcp
postgres docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp,:::5432->5432/tcp
Name Command State Ports
------------------------------------------------------------------------------------------------
pgadmin /entrypoint.sh Up 443/tcp, 0.0.0.0:5555->80/tcp,:::5555->80/tcp
postgres docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp,:::5432->5432/tcp
PostgreSql 접속
- 정상적으로 설치가 완료되었다면 pgadmin을 통해 postgresql 에 접속해서 정보를 확인할수 있다.
pgAdmin 접속 확인
- http://localhost:5555/browser/
- 접속 계정과 패스워드는 docker-compose.yml 파일에 작성된 정보이다.
- - PGADMIN_DEFAULT_EMAIL=example@pgadmin.com
- - PGADMIN_DEFAULT_PASSWORD=pgadmin
- 정상적으로 로그인이 되었다면 postgressql 서버 접속을 진행 한다.
- Servers 우 클릭 -> Register 버튼클릭
- 접속 계정 정보는 docker-compose.yml 파일에 작성된 계정 정보이다.
- environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- environment:
- 정상적으로 접속이 되었다면 아래와 같이 PostgreSql database 정보를 확인할 수 있다.
728x90
반응형