본문 바로가기
개발/server - aws, docker, ubuntu etc

docker compose로 DB 올리기(oracle, mysql, mongodb)

by 개발자종혁 2021. 5. 28.
728x90

0. download docker

https://docs.docker.com/docker-for-windows/install 

 

Redirecting…

 

docs.docker.com

 

 

1. docker-compose.yaml

version: "3.3"
services:
  oracle:
    container_name: demo_oracle
    build:
      context: ./oracle/
      dockerfile: Dockerfile
    image: demo/oracle-xe-11g:latest  # 
    environment:
      - ORACLE_ALLOW_REMOTE=true
    ports:
      - "1522:1521"
  mysql:
    container_name: demo_mysql
    command: --character-set-server=utf8 --collation-server=utf8_general_ci
    build:
      context: ./mysql/
      dockerfile: Dockerfile
    image: demo/mysql:5.7
    environment:
      - LC_ALL=C.UTF-8
      - MYSQL_DATABASE=DEMO
      - MYSQL_ROOT_PASSWORD=test1004
    ports:
      - "3306:3306"
  mongodb:
    container_name: demo_mongodb
    build: 
      context: ./mongodb/
      dockerfile: Dockerfile
    image: demo/mongo:3.6
    environment:
      - MONGO_INITDB_ROOT_USERNAME=DEMO_ADMIN
      - MONGO_INITDB_ROOT_PASSWORD=test1004!
      - MONGO_INITDB_DATABASE=demo
    ports:
      - "27018:27017"

 

 

2. DB

 

1) oracle

1-1) oracle/Dockerfile

FROM oracleinanutshell/oracle-xe-11g

# ENV ORACLE_ALLOW_REMOTE true
ADD init/*.sql /docker-entrypoint-initdb.d/

1-2) oracle/init/1_init.sql

-- 테이블 스페이스 생성
CREATE TABLESPACE TS_DEMO  datafile '/u01/app/oracle/oradata/XE/TS_DEMO.dbf' SIZE 100M AUTOEXTEND on next 100M;
-- 임시 테이블스페이스 생성
CREATE TEMPORARY TABLESPACE TS_DEMO_TEMP  TEMPFILE  '/u01/app/oracle/oradata/XE/TS_DEMO_TEMP.dbf' SIZE 100M AUTOEXTEND on next 10M;

-- 계정생성
CREATE USER DEMO  IDENTIFIED BY  "test1004"
DEFAULT TABLESPACE TS_DEMO
TEMPORARY TABLESPACE TS_DEMO_TEMP
QUOTA UNLIMITED ON TS_DEMO;

-- 접속 권한주기
GRANT RESOURCE, CONNECT to DEMO;
-- 테이블스페이스 사용권한
GRANT UNLIMITED TABLESPACE TO DEMO;

1-3 oracle/init/2_ddl.sql

CREATE TABLE DEMO.TEST_CONTENT 
(
  TEST_SEQ_NO NUMBER(19,0) NOT NULL 
, CONTENT VARCHAR(100) NOT NULL  
, CONSTRAINT PK_TEST_CONTENT PRIMARY KEY 
  (
    TEST_SEQ_NO 
  )
);


CREATE SEQUENCE  DEMO.DEMO_TEST_SEQ_NO  MINVALUE 1 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE; 

-- ALTER TABLE DEMO.TEST_CONTENT COMMENT '테스트';

 

2) mysql

2-1) mysql/Dockerfile

FROM mysql:8.0.21

ENV TZ Asia/Seoul

COPY init/*.sql /docker-entrypoint-initdb.d/

EXPOSE 3306

2-2) mysql/init/DDL.sql

CREATE TABLE `DEMO`.`TEST` 
(
  TEST_SEQ_NO INT NOT NULL AUTO_INCREMENT 
, CONTENT VARCHAR(100) NOT NULL  
, CONSTRAINT PK_TEST PRIMARY KEY 
  (
    TEST_SEQ_NO 
  )
);


ALTER TABLE DEMO.TEST COMMENT '테스트';

 

3) mongodb

 

3-1) mongodb/Dockerfile

FROM mongo:3.6

ADD init.js /docker-entrypoint-initdb.d/

ENV TZ Asia/Seoul
EXPOSE 27017

3-1) mongodb/Dockerfile

FROM mongo:3.6

ADD init.js /docker-entrypoint-initdb.d/

ENV TZ Asia/Seoul
EXPOSE 27017

3-2) mongodb/init.js

db.createUser({user: 'DEMO', pwd: 'test1004!', roles:[{"role": 'dbOwner', "db": 'demo'}] });

 

 

3. Db 생성 or 삭제

 

1). 해당 db 3개 올리기 ( --build : 내용 변경시 새로 build)

docker-compose up -d --build

2). 해당 db 3개 내리기

docker-compose down

 

 

 

https://github.com/jonghyeok34/docker_local_springboot

 

jonghyeok34/docker_local_springboot

Contribute to jonghyeok34/docker_local_springboot development by creating an account on GitHub.

github.com

 

728x90

댓글