centosdocker以及相关依赖下载
将下载文件导入对应centos系统的目录本人使用/root/docker
执行
cd /root/docker
禁止依赖检查强制安装
rpm -ivh *.rpm --nodeps --force
安装完成之后输入docker -v查看docker版本输出如下则安装完成
Docker version 17.05.0-ce, build 89658be
此处以mysql安装为例
在一台能够联网的机器上安装docker并执行
docker pull registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7
输出如下
5.7: Pulling from acs-sample/mysql
d4bce7fd68df: Pull complete
a3ed95caeb02: Pull complete
01588229585e: Pull complete
ada32b818a1a: Pull complete
ac7528e308ac: Pull complete
44e3fb8779c7: Pull complete
bfcca86efc6a: Pull complete
32da415dff2e: Pull complete
aae6d9712a36: Pull complete
3148136ce9cc: Pull complete
Digest: sha256:32ff2f404c3bd199aaec2e6d19d91d59673e40d7394732124f91dd72a2e1ed97
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7
查看镜像是否下载完成
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/ubuntu v1.0 523e7db0e264 11 minutes ago 98.3MB
ubuntu latest dd6f76d9cc90 7 days ago 122MB
hello-world latest 725dcfab7d63 8 days ago 1.84kB
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 23 months ago 360MB
名称过长修改image名称
docker tag registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql:5.7 mysql:5.7
修改完成之后查看
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test/ubuntu v1.0 523e7db0e264 12 minutes ago 98.3MB
ubuntu latest dd6f76d9cc90 7 days ago 122MB
hello-world latest 725dcfab7d63 8 days ago 1.84kB
mysql 5.7 ec7e75e5260c 23 months ago 360MB
registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql 5.7 ec7e75e5260c 23 months ago 360MB
发现多了一个强迫症可使用
docker rmi registry.cn-hangzhou.aliyuncs.com/acs-sample/mysql
删除无用镜像
由于真正要安装的机器是离线的所以需要镜像导出
docker save mysql:5.7 > /root/mysql5.7.tar
将root目录下的文件拷贝到要安装的操作系统的/root目录下并执行
docker load < /root/mysql5.7.tar
查看镜像是否导入
docker images
若镜像导入成功后启动mysql依次执行
docker create -it mysql:5.7
docker run --name mysqlserver --restart=always -e MYSQL_ROOT_PASSWORD=sgcc -d -i -p 3306:3306 mysql:5.7
注:以上命令中 --restart=always 代表容器机器重启后自动启动容器若启动时没有添加可调用docker update --restart=always xxx (xxx为容器CONTAINET ID可通过 docker ps -a 查看)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
82a19ca1582b mysql:5.7 "docker-entrypoint..." 19 hours ago Up 19 hours 0.0.0.0:3306->3306/tcp mysqlserver
可进入终端查看mysql是否安装成功
[centos@yk ~]$ docker exec -it 82a19ca1582b /bin/bash
root@82a19ca1582b:/# mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.9 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>