MYSQL(包要放在mysql)下
在opt下 创建mysql文件夹
mkdir mysql
#创建mysql目录
进入mysql的目录中
cd mysql/
#进入mysql的目录中
编写dockerfile文件
vim Dockerfile
FROM centos:7.4.1708
ADD mysql-5.6.26.tar.gz /opt
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo \
&& useradd -s /sbin/nologin mysql \
&& yum -y install gcc gcc-c++ make pcre-devel expat-devel perl ncurses-devel autoconf cmake \
&& cd /opt/mysql-5.6.26/ \
&& cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DSYSCONFIDIR=/etc -DMYSQL_DATADIR=/home/mysql/ -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock \
&& make -j2 \
&& make install \
&& cp -f support-files/my-default.cnf /etc/my.cnf \
&& cp support-files/mysql.server /etc/init.d/mysqld \
&& chown -R mysql:mysql /usr/local/mysql/ \
&& sed -i 's/^basedir/basedir=\/usr\/local\/mysql/g' /etc/init.d/mysqld \
&& sed -i 's/^datadir/datadir=\/home\/mysql/g' /etc/init.d/mysqld \
&& /usr/local/mysql/scripts/mysql_install_db --user=mysql --ldata=/var/lib/mysql --basedir=/usr/local/mysql --datadir=/home/mysql
ENV PATH /usr/local/mysql/bin:$PATH
EXPOSE 3306
ENTRYPOINT ["/usr/local/mysql/bin/mysqld_safe"]
构建mysql:new的镜像
docker build -t centos:mysql .
启动容器
docker run --name=mysql_server -d -P lnmp/mysql:latest(名称在安装完的最后一行看)
提权
docker exec -it 镜像ID /bin/bash
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
grant all privileges on *.* to 'root'@'%' localhost identified by 'abc123';
privileges on *.* to 'root'@'%' identified by 'abc123';
grant all privileges on *.* to 'root'@'%' localhost identified by 'abc123';