离线docker安装mysql 5.7

离线安装docker

1、环境:docker一般安装在linux7(内核3.1)以上。
2、安装包下载:
tgz
https://download.docker.com/linux/static/stable/x86_64/
rpm
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
3、安装
tar -xvf docker-18.06.1-ce.tgz
cp docker/* /usr/bin/
dockerd &
(官方参考文档:https://docs.docker.com/install/linux/docker-ce/binaries/#install-static-binaries)
4、测试
[root@centos75-1 ~]# docker -v
Docker version 18.06.1-ce, build e68fc7a

docker安装mysql 5.7

内网无法联网,所以在外网虚拟机把image打包出来丢到内网跑

[root@localhost tools]# docker pull mysql:5.7
[root@localhost tools]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 1e4405fe1ea9        13 days ago         437MB
[root@localhost tools]# docker run --name mysql5.7 -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
[root@localhost tools]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
d8305db28cd0        mysql:5.7           "docker-entrypoint.s鈥   25 minutes ago      Up 25 minutes       33060/tcp, 0.0.0.0:3307->3306/tcp   mysql5.7
[root@localhost tools]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      15023/sshd          
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      7186/master         
tcp6       0      0 :::3307                 :::*                    LISTEN      46323/docker-proxy  
tcp6       0      0 :::22                   :::*                    LISTEN      15023/sshd          
tcp6       0      0 ::1:25                  :::*                    LISTEN      7186/master         
[root@localhost tools]# telnet 127.0.0.1 3307
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

[root@localhost mysql5.7]# docker exec -it mysql5.7 bash
root@d8305db28cd0:/etc/mysql/conf.d# mysql -h localhost -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit

[root@localhost mysql5.7]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 1e4405fe1ea9        13 days ago         437MB
[root@localhost mysql5.7]# docker save mysql:5.7 > image-mysql5.7.tar
[root@localhost conf]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
019af25164e2        mysql:5.7           "docker-entrypoint.s鈥   About an hour ago   Up About an hour    33060/tcp, 0.0.0.0:3307->3306/tcp   mysql5.7
[root@localhost conf]# docker cp 019af25164e2:/etc/mysql /software/mysql5.7/conf #把里面的conf拿出来根据情况改,然后丢内网挂载。注意里面my.cnf是链接文件,cat复制出来好了

把从外网打包的image和conf丢到内网跑

[root@localhost ~]# yum install -y device-mapper-persistent-data lvm2
......
[root@localhost ~]# mkdir -p /software/mysql5.7/data  #数据持久化
[root@localhost ~]# mkdir -p /software/mysql5.7/conf
[root@localhost ~]# cd /software/mysql5.7
[root@localhost mysql5.7]# ls conf/    #这里的文件我从原镜像里面复制出来修改的
conf.d  my.cnf.fallback  my.conf  mysql.cnf  mysql.conf.d
[root@localhost mysql5.7]# vim start_mysql.sh   #搞个启动脚本方便点
[root@localhost mysql5.7]# cat start_mysql.sh
#dockerd &
docker run --name mysql5.7 -p 3307:3306 --restart=always --privileged=true -v $PWD/conf:/etc/mysql -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='tc0Q_O;pe&crB4h,' -e TZ='Asia/Shanghai' -d mysql:5.7 --lower_case_table_names=1
[root@localhost mysql5.7]# chmod -R 775 /software/mysql5.7
[root@localhost mysql5.7]# ./start_mysql.sh
[root@localhost mysql5.7]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
019af25164e2        mysql:5.7           "docker-entrypoint.s鈥   6 hours ago         Up 6 hours          33060/tcp, 0.0.0.0:3307->3306/tcp   mysql5.7

 

你可能感兴趣的:(Oracle)