헤르메스 LIFE

[Docker] Docker 에 MongoDB설치하기 본문

Database

[Docker] Docker 에 MongoDB설치하기

헤르메스의날개 2023. 11. 4. 23:27
728x90

이번엔 MongoDB를 설치할 예정입니다.

? mongodb 조회
C:\>docker search mongo
NAME                                                   DESCRIPTION                                      STARS     OFFICIAL   AUTOMATED
mongo                                                  MongoDB document databases provide high avai…   9914      [OK]
mongo-express                                          Web-based MongoDB admin interface, written w…   1374      [OK]
mongodb/mongodb-atlas-kubernetes-operator              The MongoDB Atlas Kubernetes Operator - Kube…   5
mongodb/mongodb-community-server                       The Official MongoDB Community Server            45
mongodb/mongodb-enterprise-server                      The Official MongoDB Enterprise Advanced Ser…   4
mongodb/mongodb-atlas-kubernetes-operator-prerelease   This is an internal-use-only build of the Mo…   0
bitnami/mongodb                                        Bitnami MongoDB Docker Image                     234                  [OK]
mongodb/atlas                                          Create, manage, and automate MongoDB Atlas r…   4
circleci/mongo                                         CircleCI images for MongoDB                      13                   [OK]
bitnami/mongodb-exporter                                                                                11
mongodb/mongodb-atlas-search                                                                            0
percona/mongodb_exporter                               A Prometheus exporter for MongoDB including …   9
bitnami/mongodb-sharded                                                                                 11
mongodb/apix_test                                      apix test repo                                   0
rapidfort/mongodb                                      RapidFort optimized, hardened image for Mong…   23
rapidfort/mongodb-ib                                   RapidFort optimized, hardened image for Mong…   10
rapidfort/mongodb-official                             RapidFort optimized, hardened image for Mong…   11
rancher/mongodb-conf                                   This container image is no longer maintained…   2
bitnamicharts/mongodb                                                                                   0
rapidfort/mongodb-perfomance-test                                                                       10
mongodb/mongo-cxx-driver                               Container image for the C++ driver               1
bitnamicharts/mongodb-sharded                                                                           0
rancher/mongodb-config                                                                                  0
litmuschaos/mongo                                                                                       1
noenv/mongo-exporter                                   Prometheus MongoDB Exporter Docker Image         2

mongo 가 많이 사용하는 이미지인 듯 합니다.  별이 많네요.

? mongo 다운로드
C:\>docker pull mongo
Using default tag: latest
latest: Pulling from library/mongo
43f89b94cd7d: Pull complete
54a7480baa9d: Pull complete
7f9301fbd7df: Pull complete
5e4470f2e90f: Pull complete
40d046ff8fd3: Pull complete
e062d62b861e: Pull complete
72919e34fde8: Pull complete
ab22810dfc64: Pull complete
fb05c29fbdf5: Pull complete
Digest: sha256:d341a86584b96eb665345a8f5b35fba8695ee1d0618fd012ec4696223a3d6c62
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest

? 다운로드된 이미지 확인
C:\>docker images
REPOSITORY              TAG       IMAGE ID       CREATED         SIZE
mongo                   latest    ee3b4d1239f1   3 weeks ago     748MB
postgres-ko             14.1      5c2063862126   6 months ago    375MB
ubuntu                  latest    08d22c0ceb15   8 months ago    77.8MB
redis                   latest    3358aea34e8c   11 months ago   117MB
mysql                   latest    d1dc36cf8d9e   21 months ago   519MB
postgres                <none>    e94a3bb61224   23 months ago   374MB
jaspeen/oracle-xe-11g   latest    52fbd1fe2d7a   7 years ago     792MB

? Docker oracle11g 컨테이너 생성
? -d : 백그라운드 실행
? -p 포트 포딩 27017번 포트로 들어온 내용은 27017번 포트로 포딩을 해주겟다는 내용
? --name Container 이름을 설정해줍니다. 
? docker exec -> run a command on an existing/running container
? docker run -> create a new container from an image, and run the command there
C:\>docker run --name mongodb_boot -d -p 27017:27017 mongo
8fbd8c8b46619cb26805aac87164defffeeabe4e9833d00ce7018bd4369a3a7b

? docker에 설치된 컨테이너 목록 조회
C:\>docker ps -a
CONTAINER ID   IMAGE                   COMMAND                   CREATED              STATUS                    PORTS                                            NAMES
8fbd8c8b4661   mongo                   "docker-entrypoint.s…"   About a minute ago   Up About a minute         0.0.0.0:27017->27017/tcp                         mongodb_boot

MongoDB 테스트

- MongoDB 버전에 따라 mongosh 또는 mongo 접속할 수 있습니다.

? Mongodb 중지
C:\>docker stop mongodb_boot
mongodb_boot

? Mongodb 시작
C:\>docker start mongodb_boot
mongodb_boot

? Mongodb 재시작
C:\>docker restart mongodb_boot
mongodb_boot

MongoDB 사용

? 컨테이너 접속
C:\>docker exec -it mongodb_boot bash

? MongoDB 접속
root@8fbd8c8b4661:/# mongosh
Current Mongosh Log ID: 65462760dbf2bf412608ca94
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.1
Using MongoDB:          7.0.2
Using Mongosh:          2.0.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting
   2023-11-04T11:05:40.715+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
   2023-11-04T11:05:41.405+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2023-11-04T11:05:41.405+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
   2023-11-04T11:05:41.405+00:00: vm.max_map_count is too low
------

? 접속에 성공하면 test Database 에 접속됩니다.
? test> 로 보여집니다.

? MongoDB Database 목록 확인
test> show dbs
admin   40.00 KiB
config  72.00 KiB
local   72.00 KiB

? 'spring' Database 생성
? use 명령 : 사용하는 Database가 없으면, 생성 후 접속합니다.
test> use spring
switched to db spring

? Collection 생성
spring> db.createCollection('spring_list');
{ ok: 1 }

? 계정생성
spring> use admin
switched to db admin
admin> db.createUser({user: "spring", pwd: "1234", roles:["root"]});
{ ok: 1 }

MongoDB GUI 클라이언트

Robo 3T ( 3T Software 에서 개발한 제품으로 Studio 3T는 유료, Robo 3T는 무료입니다. )

다운로드 받은 파일을 설치합니다.

설치 후 Activate 입니다. - Studio 3T 가 설치된 상태입니다.

- 요즘 Robo 3T 설치가 Studio 3T의 설치로 변경된 것 같습니다.

회원가입 후 로그인을 해야 합니다.

로그인 후 Robo 3T가 오픈되면, Studio 3T가 오픈됩니다. Studio 3T는 30일 Trial 버전입니다.

Go to Free 를 선택하시면, 기능이 축소된 Robo 3T 버전이 됩니다.

Disable my trial 을 선택합니다.

처음보다 메뉴가 많이 사라졌습니다.

Studio 3T Free 버전입니다.

MongoDB 접속

Connection URL : mongodb://127.0.0.1:27017

Welcom to Studio 3T 탭을 닫아버리면 아래와 같은 화면이 나옵니다.

'spring_list'를 클릭하면 InelliShell 이 오픈됩니다.

728x90