首页 > 网络 > 云计算 >

docker创建基于Ubuntu16.04安装MySQL5.7.16的镜像

2017-01-21

docker search ubuntu docker pull ubuntu:16 04 docker images -a docker run -it ubuntu:16 04 bin bash apt-get -yqq update apt-get install wget wget http: dev mysql com get mys

docker search ubuntu
docker pull ubuntu:16.04
docker images -a
docker run -it ubuntu:16.04 /bin/bash
#####
apt-get -yqq update
apt-get install wget
wget http://dev.mysql.com/get/mysql-apt-config_0.8.0-1_all.deb
apt-get update #important
apt-get install mysql-server

安装过程中需要设置MySQL root用户的密码,等待一会就安装成功了。

启动MySQL服务:

service mysql start

登录MySQL:

mysql -u root -p

自己创建镜像的导入导出:
docker commit [containerId] noname/mysql:version
docker images -a
docker save [imageId] >./mysqlserver.tar
docker load
mysql --version

基于Dockerfile创建mysql镜像

vim Dockerfile

FROM ubuntu:14.04

#RUN apt-get update
RUN apt-get -y install mysql-server
RUN /etc/init.d/mysql start \
    && mysql -uroot -e "grant all privileges on *.* to 'root'@'%' identified by '1';" \
    && mysql -uroot -e "grant all privileges on *.* to 'root'@'localhost' identified by '1';" 

RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \
    && echo 'skip-host-cache\nskip-name-resolve' | awk '{ print } $1 == "[mysqld]" && c == 0 { c = 1; system("cat") }' /etc/mysql/my.cnf > /tmp/my.cnf \
    && mv /tmp/my.cnf /etc/mysql/my.cnf

EXPOSE 3306  
CMD ["/usr/bin/mysqld_safe"]

docker build -t mysqlserver .

build中要设置MySQL root用户的密码

docker run -it -p 3306:3306 mysqlserver /bin/bash

method3:

#1    docker pull mysql

#2    docker run -v /data/var/mysql/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=kS4pJUIb mysql

#3    docker stop [CONTAINER ID]

#4    docker run -it -v /data/var/mysql/:/var/lib/mysql mysql /bin/bash

#5    mysqld_safe&

#6    grant all privileges on *.* to 'wuxiao'@'%' identified by 'password';

#7    docker cp [CONTAINER ID]:/etc/mysql/my.cnf /data/local/my.cnf

#8    docker stop [CONTAINER ID]

#9    docker run -d -p 3306:3306 -v /data/var/mysql/:/var/lib/mysql -v /data/local/my.cnf:/etc/mysql/my.cnf mysql

#10    add [CMD] to  /etc/rc.local

#11    OK!
相关文章
最新文章
热点推荐