下面看下docker-compose搭建mongodb、mysql的详细方法,内容如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
version: '3'
services:
mysqldbservice:
image: 'mysql:latest'
restart: always
container_name: mysqlcontainer
volumes:
- ./data:/var/lib/mysql
- ./my.cnf:/etc/mysql/my.cnf
- ./init:/docker-entrypoint-initdb.d/
ports:
- 3306:3306 #“宿主机端口号:容器内端口号”
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_USER: '' # 创建普通用户
MYSQL_PASSWORD: '' #普通用户密码
MYSQL_DATABASE: '' #创建一个库
mongodbservice:
# 镜像名称,不写版本号的话默认拉取最近的版本
image: mongo:latest
# 端口映射
ports:
# 宿主机端口:容器端口
- 27017:27017
# 容器数据挂载,持久化
volumes:
# 宿主机目录:容器目录:读写权限
- ./mongo:/data/db:rw
- ./configdb:/data/configdb:rw
# 设置环境变量
environment:
- TZ=Asia/Shanghai
# 容器名称
container_name: mongocontainer
|
my.cnf
1
2
3
4
5
6
7
8
9
10
|
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Custom config should go here
!includedir /etc/mysql/conf.d/
|
到此这篇关于docker-compose搭建mongodb、mysql的文章就介绍到这了,更多相关docker compose搭建mongodb内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://www.cnblogs.com/lceihen/p/15547365.html