Docker-01-Docker-将本地的Centos7系统做成Docker镜像

首先,安装docker软件

[root@localhost ~]# uname -a #查看内核版本
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# ls -l /sys/class/misc/device-mapper/ #检查Device Mapper
total 0
-r--r--r--. 1 root root 4096 Jun 29 22:38 dev
drwxr-xr-x. 2 root root    0 Jun 29 22:24 power
lrwxrwxrwx. 1 root root    0 Jun 29 22:23 subsystem -> ../../../../class/misc
-rw-r--r--. 1 root root 4096 Jun 29 22:23 uevent
[root@localhost ~]# yum install -y docker #使用yum安装docker

[root@localhost ~]# systemctl start docker #启动docker守护进程
[root@localhost ~]# systemctl enable docker #设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# ps -ef| grep docker #查看docker是否启动成功

docker info查看docker相关信息

[root@localhost ~]# docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.13.1

其次,将本地的Centos7系统做成Docker镜像

将系统进行格式转化并压缩,生成centos7-base.tar文件

[root@localhost ~]# tar --numeric-owner --exclude=/proc --exclude=/sys -cvf centos7-base.tar /

把镜像文件centos7-base.tar放到装有docker的系统上

[root@localhost ~]# docker import centos7-base.tar centos7

注意:centos7为自定义images名字


查看是否导入成功

[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos7             latest              2aa1c2607e6f        33 seconds ago      3.88 GB

最后,使用该镜像虚拟一个容器

[root@localhost ~]# docker run -it --name docker-test centos7 /bin/bash
[root@ba0adbe380c5 /]# 

 

你可能感兴趣的:(Docker,Docker)