[Docker] 몽고 MongoDB 설정
- 운영체제 / 도커
- 2025. 3. 17.

Docker를 활용하여 MongoDB, 백엔드, 프론트엔드 환경을 구성하는 방법을 정리했습니다.
MongoDB 설정
▼ 1. MongoDB는 별도로 포트를 열어줄 필요 없이 --network 설정만으로 컨테이너를 실행할 수 있습니다.
- MONGO_INITDB_ROOT_USERNAME: MongoDB의 루트 사용자 이름
- MONGO_INITDB_ROOT_PASSWORD: MongoDB의 루트 사용자 비밀번호
- -v data:/data/db: 데이터 저장을 위한 볼륨 설정
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --name mongodb \ | |
-v data:/data/db \ | |
--rm -d \ | |
--network goals-net \ | |
-e MONGO_INITDB_ROOT_USERNAME=max \ | |
-e MONGO_INITDB_ROOT_PASSWORD=secret \ | |
mongo |
백엔드 설정
▼ 2. MongoDB에 보안 연결을 설정할 때는 다음과 같은 연결 문자열을 사용합니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'mongodb://max:secret@mongodb:27017/course-goals?authSource=admin' |
▼ 3. 만약 문제가 발생한다면 MongoDB의 볼륨 연결을 확인하고, 기존 볼륨을 제거한 후 다시 실행합니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker volume ls | |
docker volume rm data |
▼ 4. 백엔드 컨테이너 실행 시 별도의 포트(80:80)를 열어주고, MongoDB와 연결하기 위해 --network 옵션을 추가합니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --name goals-backend \ | |
--rm -d \ | |
-p 80:80 \ | |
--network goals-net \ | |
goals-node |
프론트엔드 설정
▼ 5. 프론트엔드는 브라우저에서 실행되기 때문에 --network 설정이 동작하지 않습니다. 대신 3000 포트를 열어 백엔드(80 포트)와 연결합니다. 이 설정을 통해 프론트엔드와 백엔드가 정상적으로 연결될 수 있습니다. MongoDB를 포함한 전체 서비스가 원활하게 실행되는지 확인하려면 Docker 로그를 체크하는 것도 좋은 방법입니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --name goals-frontend \ | |
--rm -d \ | |
-p 3000:3000 \ | |
--network goals-net \ | |
goals-react |
▼ 6. 이와 같은 방법으로 Docker 환경에서 MongoDB, 백엔드, 프론트엔드를 손쉽게 구성할 수 있습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker logs goals-backend | |
docker logs goals-frontend | |
docker logs mongodb |
'운영체제 > 도커' 카테고리의 다른 글
[Docker] 도커 컨테이너 및 이미지 삭제 완벽 가이드 (0) | 2025.03.18 |
---|---|
[Docker] 맥에 Homebrew 로 도커 설치하기 (0) | 2025.03.11 |
[Docker] 도커 볼륨 바인드 마운트 생성과 삭제 (0) | 2025.03.10 |
[Docker] 도커 이미지 푸시하기 (0) | 2025.03.08 |
[Docker] 도커 우분투 systemctl, sbin/init 명령 가능한 이미지 만들기 (0) | 2022.11.07 |