docker-compose搭建mongodb、mysql的详细过程

下面看下docker-compose搭建mongodb、mysql的详细方法,内容如下所示:

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

[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内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(docker-compose搭建mongodb、mysql的详细过程)