도커를 활용해서 몽고디비 서버를 만들어 보아요.

 

먼저 도커 허브에서 mongo를 검색 해볼게요. mongo Official Image를 눌러서 들어가보면 아래와 같은 걸 볼 수 있어요.

오른쪽에 docker pull mongo 라고 써있는 거 클릭. 터미널에 붙여넣고 실행해볼게요.

➜  ~ docker pull mongo
Using default tag: latest
latest: Pulling from library/mongo
16ec32c2132b: Already exists 
6335cf672677: Already exists 
cbc70ccc8ebe: Already exists 
0d1a3c6bd417: Already exists 
960f3b9b27d3: Already exists 
aff995a136b4: Pull complete 
4249be7550a8: Pull complete 
4da411c5a406: Pull complete 
4b9c6ac629be: Pull complete 
377bc7e5ccfa: Pull complete 
Digest: sha256:f04183826e91223d4f65399abfc2cb6f17d708b20d28566b4a4974755839622d
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest

mongo:4.4 이미지를 먼저 다운받아놔서 몇몇 레이어는 Already exists라고 나오네요.

그럼 이제 아까 거기에서 밑으로 쭉쭉 내려가면 How to use this image라는 부분이 나와요

뒤에 :tag만 빼고 그대로 입력해요.

➜  ~ docker run --name some-mongo -d mongo
793d81f8a16958721ac3fc2baa3b255533f9708751aa259eff601a163a2279ab

그리고 방금 만든 some-mongo에 접속해서 MongoDB에 접속해보겠어요.

➜  ~ docker exec -it some-mongo bash 
root@793d81f8a169:/# mongo 
MongoDB shell version v5.0.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("448ea44f-0025-4d60-a8ec-1a5b60d61db2") }
MongoDB server version: 5.0.1
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.com/
...
>

 

정말 간단하네요. 그런데 이 상태로 사용하면 컨테이너가 사라지면 안에 있는 데이터도 같이 사라져요. 무섭네요.

그러면 어떻게 해야할까요? 그 건 도커 볼륨에 대해서 알아보면서 마저 알아봐요.

 

끝.