docker ps

반응형
MongoDB 로컬 환경 구성 (with. docker-compose)

docker-compose를 이용하여 MongoDB를 설치해 보려고 합니다.
먼저 docker-compose를 활용하여 MongoDB 컨테이너를 구성하기 위해서는 사전 작업으로 docker-desktop 설치를 우선적으로 해야 합니다.
설치가 안되신 분은 (Mac에서 Docker 설치하기)를 참고하셔서 docker-desktop 환경을 구성하시면 됩니다.

docker-compose.yml container image 추가 하기

ersion은 각 실습 환경에 맞는 docker 버전을 고려하여 작성하시면 됩니다. yml작성은 idl 등을 이용하시면 작성하시는데 도움이 됩니다.

version: '3'

services:
  mongo1:
      image: mongo:4.4.5
      container_name: mongo1
      expose:
        - 27017
      ports:
        - 27017:27017      
      entrypoint: [ "/usr/bin/mongod", "--bind_ip_all", "--replSet", "r0" ]

docker-compose 명령어

  • docker-compose up //실행
  • docker-compose down //종료
  • docker ps //container 프로세스 확인

docker-compose up 명령어를 사용하여 컨테이너를 실행합니다.

> docker-compose up

Docker Compose is now in the Docker CLI, try `docker compose up`

Creating network "docker_default" with the default driver
Creating mongo1       ... done

mongo1       | {"t":{"$date":"2022-06-30T03:40:07.225+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
mongo1       | {"t":{"$date":"2022-06-30T03:40:07.228+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
mongo1       | {"t":{"$date":"2022-06-30T03:40:07.228+00:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}

error log 없이 컨테이너가 올라왔다면 docker ps 명령어를 사용하여 생성된 컨테이너의 상태를 확인해 봅니다.

> docker ps

CONTAINER ID   IMAGE         COMMAND                  CREATED       STATUS       PORTS                                 NAMES
dc0c851d73a7   mongo:4.4.5   "/usr/bin/mongod --b…"   1 hours ago   Up 1 hours   0.0.0.0:27017->27017/tcp              mongo1

mongodb container 접속 하기

먼저 docker container terminal로 접속 후, 아래와 같이 정상적으로 mongo shell로 이동해 보겠습니다.

> docker exec -it mongo1 bash

root@dc0c851d73a7:/# mongo 
MongoDB shell version v4.4.5
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("74aea9a1-e1b8-4367-ab9e-02b0d96cce37") }
MongoDB server version: 4.4.5
---
The server generated these startup warnings when booting:
        2022-06-30T03:40:07.230+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2022-06-30T03:40:07.727+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2022-06-30T03:40:07.727+00:00: You are running this process as the root user, which is not recommended
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

MongoDB compass tool로 접속 하기

다양한 GUI Tool 중 compass를 이용하여 MongoDB에 접속해 보겠습니다. compass tool은 해당 링크에서 다운로드 가능합니다.
아래와 같이 정상적으로 접속이 되면 개발을 위한 MongoDB 환경 구성은 성공적으로 마무리 되었습니다.

오늘은 docker-compose를 활용한 로컬 환경 구성에 대하여 실습해 봤습니다.

반응형

+ Recent posts

반응형