-
Docker, postgres, adminer 이용해서 테스트 디비 구성하기카테고리 없음 2023. 2. 19. 00:26
로컬에서 테스트 시에 사용하기 좋은 디비 환경 구성을 도커를 이용해서 해 보겠어요.
도커는 설치되어 있다고 가정합니다.
아래 코드를 복사해서 docker-compose.yaml 로 파일을 만들어요.
version: '3.1' services: db: image: postgres restart: always container_name: postgres # 컨테이너 이름 설정 environment: POSTGRES_USER: user POSTGRES_PASSWORD: pass POSTGRES_DB: todos ports: - 5432:5432 # 외부 노출 포트 adminer: image: adminer restart: always container_name: postgres-adminer # 컨테이너 이름 설정 ports: - 8080:8080 # 외부 노출 포트
터미널로 들어 갑니다.
docker-compose.yaml 파일이 있는 디렉토리에서 docker-compose를 실행합니다.
docker-compose up -d
localhost:8080 을 오픈합니다.
open localhost:8080
System 이 디폴트로 MySql이 선택되어 있어요. 꼭 PostgreSQL 로 변경합니다.
정상적으로 접속이 되었어요.
다른 db client 툴을 이용해서도 접속 가능해요.
localhost:5432
username: user
password: pass
mysql도 같은 방법으로 접속할 수 있어요.
# Use root/example as user/password credentials version: '3.1' services: db: image: mysql # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password # (this is just an example, not intended to be a production configuration) command: --default-authentication-plugin=mysql_native_password restart: always environment: MYSQL_ROOT_PASSWORD: pass MYSQL_DATABASE: todos ports: - 3306:3306 adminer: image: adminer restart: always ports: - 8080:8080