智能云改-docker云迁移实战
本次安装的linux版本是centos7.4,docker安装不依赖任何环境,但是必须要连接网络,满足这一点就可以进行docker安装了。
一、安装:
1.删除就版本的docker输入命令:
yum -y remove docker \
docker-common \
docker-selinux \
docker-engine
2.使用命令查询docker配置文件包:
find / -name docker并逐个删除
3.安装开始,首先安装所需的软件包:
yum install -y yum-utils device-mapper-persistent-data lvm2
4.配置软件源,使用下列命令设置 stable 镜像仓库
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5.更新 yum 软件包索引
yum makecache fast
6.安装最新版本的 Docker
yum -y install docker
7.启动docker
systemctl start docker
[root@ecs-d2eb-0802001 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/tomcat latest 96c4e536d0eb 7 days ago 506 MB
docker.io/centos latest 67fa590cfc1c 8 days ago 202 MB
docker.io/mysql latest 62a9f311b99c 2 weeks ago 445 MB
[root@ecs-d2eb-0802001 ~]# docker run --name docker-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=wzy123 -d mysql
b5bc2e8cbfb1af35583e5ec0c585421e3355c628ab36c4540fc7c1d4d1c5c578
[root@ecs-d2eb-0802001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5bc2e8cbfb1 mysql "docker-entrypoint..." 3 minutes ago Up 3 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp docker-mysql
56136c8501dc tomcat:latest "catalina.sh run" 4 hours ago Up 4 hours 0.0.0.0:7890->8080/tcp ecstatic_edison
[root@ecs-d2eb-0802001 ~]# docker exec -it docker-mysql bash
root@b5bc2e8cbfb1:/# mysql -uroot -p
mysql> alter user 'root'@'%' identified with mysql_native_password by 'root';
工具连接docker里面mysql:
我们可以通过以下命令将容器保存为镜像
[root@ecs-d2eb-0802001 ~]# docker commit docker-mysql mysqlback
sha256:79a351c6cd4103f8b66cdb7ee8c63c6cd993d7240c1a44f7d4e066c2d7074034
镜像备份
[root@ecs-d2eb-0802001 ~]# docker save -o mysqlback.tar mysqlback
然后执行此命令进行恢复
docker load -i mynginx.tar
-i 输入的文件
执行后再次查看镜像,可以看到镜像已经恢复
docker导出导入:
[root@ecs-d2eb-0802001 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b5bc2e8cbfb1 mysql "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp docker-mysql
56136c8501dc tomcat:latest "catalina.sh run" 5 hours ago Up 5 hours 0.0.0.0:7890->8080/tcp ecstatic_edison
[root@ecs-d2eb-0802001 ~]# docker export -o mysql.tar docker-mysql
[root@ecs-d2eb-0802001 ~]# docker import mysql.tar wzy:imp
sha256:c4dd9cd76f4e91d5f5c2d7cf6d812ec18ecb490bd9f30ff67b259edd7a121fbb