Example of Docker image management in CentOS6

Source: Internet
Author: User
Tags commit ssh centos docker run

Image is the soul of Docker

Docker images are the basis for running Docker containers. To learn about Docker, it is very important to use images.
The image downloaded using the default docker command is made externally, and I want to create an image from the beginning and manage it myself.
This article uses Docker to create an image under CentOS 6 and records the process in detail.

Understanding Images and containers

What is the relationship between an image and a container?

The image is static and the container is dynamic.
Container is the embodiment after the image runs
Common image commands

View images

Docker images

Save the image as a tar package

Docker save centos6-mytest> centos6-mytest.tar

Load the exported tar package as an image

Docker load centos6-mytest.tar

Create basic image

Download the image production tool febootstrap

Yum-y install febootstrap


Use febootstrap to make an image (Image for CentOS6), and the image directory is a centos6-image. About 335 MB

# The basic usage of febootstrap is febootstrap [-- options] repo target [MIRROR]. You can install the corresponding package-I package name based on the actual situation.

Febootstrap-I bash \
-I wget-I yum-I iputils-I iproute-I man-I vim-minimal \
-I openssh-server-I openssh-clients-I cronie-anacron-I crontabs-I rsyslog \
Centos6 centos6-image http://mirrors.aliyun.com/centos/6/ OS /x86_64/


Import the image to docker

Cd centos6-image & tar-c. | docker import-centos6-base


Verify image availability


Docker images # you can see the centos6-base just created
Docker run-t-I centos6-base/bin/bash # you can create a container and enter the bash command line


Create an application image

The basic image only contains the basic system, but it does not contain the actual application and does not have a practical effect.
We need to add applications on the base system and generate new images. There are two methods: one is Docker File.

Use Docker File to create a new image

Compile a Docker file. Vim Dockerfile

# Dockerfile
FROM centos6-base
MAINTAINER Yonghua
RUN sed-ri's/session required pam_loginuid.so/# session required pam_loginuid.so/g'/etc/pam. d/sshd
RUN mkdir-p/root/. ssh & chown root. root/root & chmod 700/root/. ssh
EXPOSE 22
RUN echo 'root: 123456 '| chpasswd
Env lang en_US.UTF-8
ENV LC_ALL en_US.UTF-8
CMD/usr/sbin/sshd-D
# End

Use docker build to generate a new image

Docker build-t centos6-ssh. # The Last. Represents the path of the Dockerfile
Okay, you can see the newly created image centos6-ssh through the docker images command

Docker images # you can see the image

Directly commit the Container into an image

DockerFile uses a defined method to create an image, and sometimes we expect to obtain the image by converting the Container into an image.

First, create a container and enter bash for customization.

Docker run-t-I centos6-base/bin/bash
Then use the commit command to convert the container into an image.

# Docker commit CONTAINER_ID IMAGE_NAME
Docker commit 83a9fb9eeefd centos6-mytest

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.