docker安装mysql挂载数据到宿主机

第一种方式

# 拉取mysql
docker pull mysql:5.7
# 创建root用户实例并启动
docker run -p 50207:3306 --name mysql0207 --restart=always -v /mnt/docker/MySQL0207/log:/var/log/mysql -v /mnt/docker/MySQL0207/data:/var/lib/mysql -v /mnt/docker/MySQL0207/conf:/etc/mysql -v /etc/localtime:/etc/localtime -e MYSQL_ROOT_PASSWORD=wugz1019 --net wgz-network -d mysql:5.7

第二种方式docker-compose安装

创建docker-compose.yml文件

version: '3'
services:
  mysql:
    image: 'mysql:5.7'
    container_name: mysql3306
    restart: always
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: "wugz1019"
      MYSQL_USER: 'root'
      MYSQL_PASS: 'wugz1019'
      # 这里是重点
    networks:
      - wgz-network-1
    volumes:
      - '/home/docker/mysql3306/log:/var/log/mysql'
      - '/home/docker/mysql3306/data:/var/lib/mysql'
      - '/home/docker/mysql3306/conf:/etc/mysql'
      - '/etc/localtime:/etc/localtime'
# 这里是重点
networks:
  wgz-network-1:
    external: true
创建网络wgz-network-1
docker network create --subnet=174.1.1.0/24 wgz-network-1

你可能感兴趣的:(docker,mysql,容器)