起因
开发中经常需要快速部署一台随用随关的数据库服务器,如mysql,oracle,mongodb,elastic-search
尝试
一直觉得docker特别方便,加上docker-compose.yaml简直如虎添翼
解决方案
新建目录并选择需要的服务器,写入docker-compose.yaml,执行docker-compose up -d
即可。
ps1. 如需要,请自行依据对应镜像主页说明,修改镜像版本和密码等参数
ps2. 如果不能启动,请尝试sudo chmod 774 data/修改目录权限
mysql
version: '2'
services:
mysql_db:
restart: always
image: mysql:8
command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
environment:
MYSQL_ROOT_PASSWORD: root123456
ports:
- 127.0.0.1:3306:3306
volumes:
- ./data:/var/lib/mysql
oracle
version: '2'
# https://hub.docker.com/r/datagrip/oracle
# username: system
# password: oracle
services:
oracle_db:
restart: always
image: sath89/oracle-xe-11g
ports:
- 127.0.0.1:1521:1521
volumes:
- ./data:/u01/app/oracle
mongodb
mongo_master:
restart: always
image: mongo:4.0
ports:
- 127.0.0.1:27017:27017
volumes:
- ./data:/data/db
elasticsearch
elasticsearch_master:
restart: always
image: elasticsearch:7.1.0
hostname: elasticsearch
environment:
discovery.type: single-node
ports:
- 127.0.0.1:9200:9200
volumes:
- ./data:/usr/share/elasticsearch/data