Skip to content

Commit

Permalink
[karrot-0009] DB 설계 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
tae0y committed Apr 23, 2023
1 parent 7a94bda commit 65a2177
Show file tree
Hide file tree
Showing 5 changed files with 447 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docker/Dockerfile-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM postgres:15

RUN apt-get update && apt-get install -y postgresql-15-postgis

CMD ["/usr/local/bin/docker-entrypoint.sh","postgres"]
32 changes: 32 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.8'
services:
db:
container_name: pg_container
# image: postgres
build:
context: .
dockerfile: Dockerfile-db
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: test_db
ports:
- "5432:5432"
volumes:
- ./db:/docker-entrypoint-initdb.d/
- ./db.sql:/docker-entrypoint-initdb.d/init-ddl.sql
- ./db.sql:/docker-entrypoint-initdb.d/init-data.sql
- database_volume:/var/lib/postgresql/data
pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"

volumes:
database_volume:
27 changes: 27 additions & 0 deletions docker/docker-readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# docker readme

> 도커 컴포즈로 개발DB 올리는 방법을 소개합니다!
`docker-compose.yml` 디렉토리에서 명령어를 실행한다.
```shell
docker compose up
```

- pgadmin은 `localhost:5050`처럼 로컬호스트로 접속한다.
- pgadmin에서 db에 접속할때는 아래 명령어로 IP를 확인한다.
```shell
docker ps | grep pg_container | awk '{print $1}'
docker inspect af84 | grep IPAddress
```

postgis등 관련 라이브러리 설치를 위해 도커 빌드파일을 구성해줬다.
```text
FROM postgres:14.1
RUN apt-get update && apt-get install -y postgresql-14-postgis-3
CMD ["/usr/local/bin/docker-entrypoint.sh","postgres"]
```

또는, 도커가 올라오면 터미널에 직접 붙어서 설치해줘도 된다.
```shell
apt-get update && apt-get install -y postgresql-14-postgis-3
```
Empty file added docker/init-data.sql
Empty file.
Loading

0 comments on commit 65a2177

Please sign in to comment.