Docker: Create Image from Container

Docker: Create Image from Container

I’m going to create my own image from a running container for further sharing. So, I’m planning to get a container as base, run it, commit as Image, export image as a file and share with friends, and finally be loaded by them.

Here I list the steps:

Base container

Get a base Image

docker pull centos

Run a base Container

docker run -it centos /bin/bash

Update Container

Modify Container

I will create a file /usr/local/bin/echo, with content:

#!/bin/bash
echo "hi, $@"

and make it executable.

# chmod a+x echo

See Container status

docker ps -a

Terminal message:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                                              NAMES
c71580983e83        centos              "/bin/bash"              44 seconds ago      Exited (0) 3 seconds ago                                                      echo

Now we get container id: c71580983e83

Create Image

Commit Container as Image

Save the image as echo:v1, which name echo with tag v1.

docker commit -m "echo container" -a "wang xiaoqiang" c71580983e83 echo:v1

See the images

docker images

Terminal text:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
echo                v1                  511b808ecb31        12 seconds ago      196.7 MB

So we get the image locally 511b808ecb31 in name echo:v1.

Use Image

Save Image

docker save echo:v1 >echo-v1.tar

Load Image

docker load < echo-v1.tar

Terminal text:

8db4df206a2d: Loading layer [==================================================>]  5.12 kB/5.12 kB

Then image can be loaded in local repository.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值