当前位置:   article > 正文

Dockerfile制作基于Ubuntu的MySQL镜像_ubuntu mysql dockerfile

ubuntu mysql dockerfile

基于ubuntu18.04制作MySQL的docker镜像

通过dockefile

1.版本信息
  • 镜像源:https://ogec0pyk.mirror.aliyuncs.com(阿里)
  • Ubuntu:18.04
  • MySQL:5.7
2.步骤
  1. 编写Dockerfile

     FROM ubuntu
     #将sources.list复制到镜像下的/etc/apt/下面,修改镜像源地址
     ADD sources.list /etc/apt/
     #将run.sh脚本复制到镜像中(我这里随便找的路径)
     ADD run.sh /home/
     #更新apt,因为更换了sources.list,所以比较快,使用官方镜像源在国外,速度特慢
     RUN apt-get clean && apt-get update
     #安装MySQL
     RUN apt-get -y install mysql-server
     RUN chmod +x /home/run.sh
     EXPOSE 3306 
     CMD ["/home/run.sh"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
  2. 编写sources.list如下,使用的是阿里的,可在官网查找其他版本的

    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

3.编写run.sh

#!/bin/bash
sed -i 's/127.0.0.1/0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
service mysql start
mysql -uroot -e "grant all privileges on *.* to 'root'@'%' identified WITH mysql_native_password by '123456';" 
mysql -uroot -e "grant all privileges on *.* to 'root'@'localhost' identified WITH mysql_native_password by '123456';" 
service mysql restart
/bin/bash
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4.构建镜像
docker build -t lyfts:v4 .
在这里插入图片描述
镜像构建成功

  1. 启动容器
    docker run -itd --name dfmysq4 -p 3323:3306 lyfts:v4
  2. 执行启动脚本,我将run.sh复制到/home目录下的
    docker exec -i 容器id /home/run.sh
  3. 远程连接测试(MySQL已经启动成功)
    在这里插入图片描述

到此结束,如有问题,请留言!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/543016
推荐阅读
相关标签
  

闽ICP备14008679号