본문 바로가기

* 리눅스

[리눅스] mongodb, mongo-express 도커 컨테이너 올리기

반응형

mongodb, mongo-express 도커 컨테이너 올리기

docker-compose.yml 편집

version: '3.9'
services:

  ### Mongodb Servers
  mongo1:
    image: anti1346/mongo:5.0.8
    container_name: mongo1
    restart: unless-stopped
    env_file:
      - .env
    environment:
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
      - TZ=Asia/Seoul
    command: mongod --auth --replSet rs1 --keyFile /data/key/mongo.key --dbpath /data/db --bind_ip_all
    volumes:
      - ./mongodb/data-mongo1:/data/db
    ports:
      - 27017:27017
    expose:
      - 27017
    networks:
      - mongo-net


  ### mongo-express
  mongo-express:
    image: mongo-express:latest
    container_name: mongo-express
    restart: always
    environment:
      ME_CONFIG_MONGODB_URL: mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@mongo1:27017/
    depends_on:
      - mongo1
    ports:
      - 8080:8081
    expose:
      - 8081
    networks:
      - mongo-net


networks:
  mongo-net:

.env 편집

#####MONGODB
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=changeme
MONGO_INITDB_DATABASE=admin
MONGO_REPLICA_SET_NAME=rs0

#####MONGOEXPRESS
MONGO_ROOT_USER=root
MONGO_ROOT_PASSWORD=changeme
MONGOEXPRESS_LOGIN=root
MONGOEXPRESS_PASSWORD=changeme

mongodb 디렉터리 생성 및 디렉토리 권한 변경

mkdir mongodb
chown 999:999 mongodb

도커 컴포즈 시작

docker-compose up -d
docker-compose ps
$ docker-compose ps
    Name                   Command               State            Ports
---------------------------------------------------------------------------------
mongo-express   tini -- /docker-entrypoint ...   Up      0.0.0.0:8080->8081/tcp
mongo1          docker-entrypoint.sh mongo ...   Up      0.0.0.0:27017->27017/tcp

express 웹 브라우저 확인

http://{serverip}:8080

728x90
반응형