일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- qsort
- sort
- Algorithm
- 13305
- list
- '0'
- 구현
- function_template
- Articulation_Point
- Critical_Path_Analysis
- template
- deletion
- Biconnected_Component
- 총정리
- red-black tree
- Heap
- 5397
- sstream
- 예제
- 자료구조
- 백준
- class_template
- c++
- data_structure
- 알고리즘
- STL
- connected_component
- Pair
- 문법
- singly Linked List
- Today
- Total
- Today
- Total
- 방명록
어제의 나보다 성장한 오늘의 나
[Docker] 도커에 몽고 DB를 설치하고 실행 시키기 본문
몽고 디비를 로컬에 직접 설치하지 않고 도커 컨테이너 안에 설치하여 접속하여 사용해보는 방법을 알아보자.
1. 도커 설치
도커 공식홈페이지에서 도커를 설치한다.
https://www.docker.com/get-started/
Get Started | Docker
Get started with Docker Desktop and join millions of developers in faster, more secure app development using containers and beyond.
www.docker.com
~ docker -v
Docker version 24.0.7, build afdd53b
2. 몽고 디비 이미지를 Docker Hub로 부터 설치한다.
설치
docker pull mongo
이미지 확인
~ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest 545fe6e3d65b 4 weeks ago 721MB
3. 도커 컨테이너 생성 / 실행
컨테이너 실행
docker run --name container_name -d -p 27017:27017 mongo
--name : 컨테이너 이름 지정
-d : 백 그라운드 실행
-p : 포트를 연결해준다. ( 27017:27017 -> 로컬의 27017 포트와 컨테이너의 27017포트를 연결 )
실행 중인 컨테이너 확인
~ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ca17f96a34cd mongo "docker-entrypoint.s…" 8 minutes ago Up 8 minutes 0.0.0.0:27017->27017/tcp mongo-container
‼ 참고로 모든 컨테이너 (종료된 컨테이너 포함) 를 보려면 ps에 -a를 붙여 주면 된다.
-a, --all Show all containers (default shows just running)
4. 컨테이너에 접속
1) bash로 접속
-it : 대화형 상호 작용을 위한 옵션으로, 터미널 입력 및 출력을 활성화하여 사용자가 컨테이너 내부의 명령어를 실행하고 상호 작용할 수 있게 한다.
~ docker exec -it mongo-container bash
root@ca17f96a34cd:/ ls
bin data docker-entrypoint-initdb.d home lib mnt proc run srv tmp var
boot dev etc js-yaml.js media opt root sbin sys usr
2) mongosh로 접속
~ docker exec -it mongo-container mongosh
Current Mongosh Log ID: 65bdefd8c8aebdd642b2972e
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.1
Using MongoDB: 7.0.5
Using Mongosh: 2.1.1
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2024-02-03T07:23:00.248+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2024-02-03T07:23:00.674+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2024-02-03T07:23:00.674+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2024-02-03T07:23:00.675+00:00: vm.max_map_count is too low
------
컨테이너 실행할 때 -p로 포트 매핑을 했었다면 로컬에서
~ mongosh
만쳐도 접속 할 수 있다.
이렇게 로컬과 포트 매핑 까지 해두면 개발할 때 로컬 환경에서 도커의 몽고 디비를 연결해서 사용할 수 있다!