Linux使用docker安装mysql

2021/9/16 2:06:52

本文主要是介绍Linux使用docker安装mysql,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

步骤1:

安装docker与docker-compose

#!/bin/bash
echo "开始安装 docker"
sudo yum install -y yum-utils
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install -y docker-ce docker-ce-cli containerd.io

sudo systemctl enable docker
sudo systemctl start docker

#echo "拉取 hello-world 仓库"
# sudo docker run hello-world

#echo "设置阿里云源"
#sudo yum-config-manager \
#    --add-repo \
#    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

docker --version

echo "开始安装 docker-compose "
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version

步骤2:

编写docker-compose.yaml文件

version: "3"
services:
  mysql:
    container_name: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=123456
    image: mysql:8.0.16
    logging:
      driver: json-file
      options:
         max-size: "1g"
    ports:
      - 3306:3306/tcp
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - /home/data/mysql:/var/lib/mysql
      - /home/data/config/my.cnf:/etc/mysql/my.cnf

步骤3:

编写好my.cnf文件与创建数据库映射目录

在docker-compose.yaml当前目录执行docker-compose up -d



这篇关于Linux使用docker安装mysql的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程