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內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: