欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

镜像基本操作: 导入镜像 导出镜像 启动镜像

程序员文章站 2022-03-14 10:00:03
...

2.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:docker镜像

1)下载镜像

[aaa@qq.com ~]# docker pull docker.io/busybox
[aaa@qq.com bulid]# docker pull docker.io/busybox
Using default tag: latest
Trying to pull repository docker.io/library/busybox ... 
latest: Pulling from docker.io/library/busybox
Digest: sha256:061ca9704a714ee3e8b80523ec720c64f6209ad3f97c0ff7cb9ec7d19f15149f

2)上传镜像

[aaa@qq.com ~]# docker push docker.io/busybox

3)查看镜像

[aaa@qq.com ~]# docker images
REPOSITORY           TAG                 IMAGE ID         CREATED             SIZE
docker.io/busybox    latest         d8233ab899d4        10 days ago         1.199 MB

4)查找busybox镜像

[aaa@qq.com ~]# docker search docker.io/busybox

5)导出busybox镜像为busybox.tar

[aaa@qq.com ~]# docker save docker.io/busybox:latest -o busybox.tar
[aaa@qq.com ~]# ls
busybox.tar  

6)导入镜像

[aaa@qq.com ~]# scp nginx.tar aaa@qq.com:/root
[aaa@qq.com ~]# ls
nginx.tar  
[aaa@qq.com ~]# docker load -i nginx.tar
3c816b4ead84: Loading layer 58.47 MB/58.47 MB
787822cf1b17: Loading layer 54.44 MB/54.44 MB
89decbdf7fb7: Loading layer 3.584 kB/3.584 kB
Loaded image: docker.io/nginx:latest/3.584 kB 
[aaa@qq.com ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx     latest              42b4762643dc        4 weeks ago         109.2 M             e1ddd7948a1c        4 weeks ago      1.163 MB

7)删除镜像

[aaa@qq.com docker]# docker rmi  docker.io/nginx
Untagged: docker.io/nginx:latest
Deleted: sha256:42b4762643dcc9bf492b08064b55fef64942f055f0da91289a8abf93c6d6b43c
Deleted: sha256:e0e55dd2303b3e3ec852acae267d1f8a3eea27a22c64a5829304ecee4d3f559c
Deleted: sha256:4062cf272cdd99e83b1c21f712e5e1359c91ecf92925e56c62133c3324b84e45
Deleted: sha256:3c816b4ead84066ec2cadec2b943993aaacc3fe35fcd77ada3d09dc4f3937313

步骤二:一次性导入多个镜像

[aaa@qq.com 04]$ cd /linux-soft/04/
[aaa@qq.com 04]$ scp -r docker/ aaa@qq.com:/root/
[aaa@qq.com ~]# cd docker
[aaa@qq.com docker]# ls
centos.tar  nginx.tar  redis.tar  registry.tar  ubuntu.tar
[aaa@qq.com docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[aaa@qq.com docker]# for i in * ; do docker load -i $i; done
bcc97fbfc9e1: Loading layer 208.2 MB/208.2 MB
Loaded image: docker.io/centos:latest208.2 MB
Loaded image: docker.io/nginx:latest
a098f8909d23: Loading layer 338.4 kB/338.4 kB
c3bc3362d4ff: Loading layer 3.034 MB/3.034 MB
bf10d8534af6: Loading layer  36.4 MB/36.4 MB
0949ce28adcc: Loading layer 1.536 kB/1.536 kB
b1f287cac208: Loading layer 3.584 kB/3.584 kB
Loaded image: docker.io/redis:latest/3.584 kB
7bff100f35cb: Loading layer 4.672 MB/4.672 MB
6b6e0aba7201: Loading layer 1.587 MB/1.587 MB
18429e86e6ad: Loading layer 20.08 MB/20.08 MB
7b33b7de3d52: Loading layer 3.584 kB/3.584 kB
726e86b708de: Loading layer 2.048 kB/2.048 kB
Loaded image: docker.io/registry:latest048 kB
adcb570ae9ac: Loading layer 89.95 MB/89.95 MB
7604c8714555: Loading layer 15.87 kB/15.87 kB
9e9d3c3a7458: Loading layer 11.26 kB/11.26 kB
27a216ffe825: Loading layer 3.072 kB/3.072 kB
Loaded image: docker.io/ubuntu:latest3.072 kB
[aaa@qq.com docker]# docker images

导入多个镜像如图-1所示:
镜像基本操作: 导入镜像 导出镜像 启动镜像

图-1
步骤三:启动镜像

1)启动centos镜像生成一个容器

启动镜像时若不知道后面的命令加什么:

1、可以猜(如:/bin/bash、/bin/sh)

2、可以不加后面的命令,默认启动

[aaa@qq.com docker_images]# docker run -it docker.io/centos /bin/bash
[aaa@qq.com /]# ls /
anaconda-post.log  bin  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[aaa@qq.com /]# cd /etc/yum.repos.d/
[aaa@qq.com yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[aaa@qq.com yum.repos.d]# rm -rf C*
[aaa@qq.com yum.repos.d]# ls
[aaa@qq.com yum.repos.d]#vi dvd.repo    //在容器里面配置一个yum源
[local]
name=local
baseurl=ftp://192.168.1.254/system
enable=1
gpgcheck=0
[aaa@qq.com yum.repos.d]# yum -y install net-tools  //安装软件
[aaa@qq.com yum.repos.d]# exit
exit
相关标签: CLOUD