您的位置:首页 > 运维架构 > Docker

Docker: Create Image from Container

2016-07-31 23:50 453 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Docker