创建工作目录
mkdir mysql
cd mysql/
创建并编写Dockerfile
使用vim Dockerfile
创建Dockerfile文件并添加以下内容:
FROM guyton/centos6
MAINTAINER The CentOS Project <[email protected]>
RUN sed -i 's|^mirrorlist=|#mirrorlist=|g' /etc/yum.repos.d/CentOS-Base.repo
RUN sed -i 's|^#baseurl=http://mirror.centos.org|baseurl=https://vault.centos.org|g' /etc/yum.repos.d/CentOS-Base.repo
RUN yum install -y mysql mysql-devel mysql-server
RUN /etc/init.d/mysqld start && \
mysql -e "grant all privileges on *.* to 'root'@'%'identified by '123456';" && \
mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by '123456';"
EXPOSE 3306
CMD ["mysqld_safe"]
生成镜像
使用docker build -t centos:mysql .
生成mysql镜像
启动容器
使用docker run --name=mysql_server -d -P centos:mysql
启动容器
验证
本地安装mariadb
本地登录MySQL数据库验证