Making a Docker image

Source: Internet
Author: User
Tags docker ps

There are two ways to make a Docker image.

First, use the Docker commit command to make a docker image

1. Pull a centos6.6 base image and run a Docker container, then customize it (install, configure the service, etc.);

[email protected] ~]# Docker pull centos:6.6
Pulling Repository CentOS
8b44529354f3:download Complete
F1b10cd84249:download Complete
status:downloaded newer image for centos:6.6
[email protected] ~]# Docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
CentOS 6.6 8b44529354f3 4 days ago 202.6 MB
CentOS centos6.6 8b44529354f3 4 days ago 202.6 MB
[[email protected] ~]# Docker run-i-T centos:6.6 bash
[[email protected]/]# ls
Bin Dev etc home Lib lib64 lost+found media mnt opt proc root sbin selinux SRV sys tmp usr var
[Email protected]/]# Mkdir/tmp/test.txt
[[Email protected]/]# exit
Exit

Next, take a look at the container changes:

[email protected] ~]# Docker ps-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
B42C1BA929A9 centos:6.6 "Bash" about a minute ago Exited (0) seconds ago Berserk_mcclintock
804a56ce8008 f1b10cd84249 "/bin/echo hello", minutes ago Test
[email protected] ~]# Docker diff b42c1ba929a9
C/tmp
A/tmp/test.txt
C/root
A/root/.bash_history

2. Execute the Docker commit command to create a mirror:

[email protected] ~]# Docker commit-m "New container" b42c1ba929a9 yuanhuan/newcontainer1
07b146e0be9e98c253122784c3837dd1604f7692e794f3601dad747d41901cd4
[email protected] ~]# Docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Yuanhuan/newcontainer1 latest 07b146e0be9e seconds ago 202.6 MB
CentOS 6.6 8b44529354f3 4 days ago 202.6 MB
CentOS centos6.6 8b44529354f3 4 days ago 202.6 MB

3. Log in to Docker and push the image to the Docker repository:

[email protected] ~]# Docker Login
Username:yuanhuan
Password:
Email: [Email protected]
Login succeeded
[email protected] ~]# Docker push Yuanhuan/newcontainer1
The push refers to a repository [Yuanhuan/newcontainer1] (Len:1)
Sending image list
Pushing repository Yuanhuan/newcontainer1 (1 tags)
F1b10cd84249:image already pushed, skipping
8b44529354f3:image already pushed, skipping
07b146e0be9e:image successfully pushed
Pushing tag for Rev. [07b146e0be9e] on {https://cdn-registry-1.docker.io/v1/repositories/yuanhuan/newcontainer1/tags/ Latest

Once successful, you can log into the Docker page and see the image you just made.

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;border-bottom:0px;border-left:0px; " Border= "0" alt= "image" Src= "http://s3.51cto.com/wyfs02/M00/6B/FE/wKiom1U8vdrCXWYKAADhUCdiGfM960.jpg" height= "232" />

Second, use Dockerfile to make image

Create the Dockerfile file: Dockerfile.txt, which reads as follows:

from CentOS          
Maintainer YH, http://yuanhuan.blog.51cto.co M            
RUN yum install passwd OpenSSL openssh-server-y       &NBSP ;   &NBSP
Run echo ' 123456 ' | passwd--stdin root            
Run Ssh-keygen-q-t Rsa-b 2048-f/etc/ssh/ssh_host_rsa_key-n '            
RUN ssh-keygen-q-T Ecdsa-f /etc/ssh/ssh_host_ecdsa_key-n '            
RUN sed-i '/^session\s\+required\s\+pam_l oginuid.so/s/^/#/'/etc/pam.d/sshd            
RUN mkdir-p/root/.ssh && chown R Oot.root/root && chmod 700/root/.ssh           &NBSP
EXPOSE            
CMD IP addr ls eth0 | awk ' {print $} ' | Egrep-o ' ([0-9]+\.) {3} [0-9]+ ';/usr/sbin/sshd-d

Brief description: The main purpose of the dockerfile is to open the sshd service so that SSH can be logged in and the root user's password is set.

Then execute the following command to make an image:

Docker build-t Centos:autosshd-< Dockerfile.txt

Once successful, you can view the list of images with Docker images.

Two ways to compare:

The use of the commit command is relatively simple, the equivalent of Docker based on container internal execution of the command automatically generated Dockerfile, and build, more suitable for dockerfile unfamiliar users;

The dockerfile approach is slightly more complex, but more suitable for batch processing scenarios. Dockerfile Write once, run multiple times.

This article is from the "fireworks easy to cool" blog, please be sure to keep this source http://yuanhuan.blog.51cto.com/3367116/1638753

Making a Docker image

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.