What is docker?
Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications. consisting of docker engine, a portable, lightweight runtime and packaging tool, and docker hub, a cloud service for sharing applications and automating workflows, docker enables apps to be quickly assembled from components and eliminates the friction between development, QA, and production environments. as a result, it can ship faster and run the same app, unchanged, on laptops, data center VMS, and any cloud. (officially defined)
Differences between docker and Virtual Machine
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4C/99/wKiom1RA1dzSD2BeAABtDdplgB0796.jpg "style =" float: none; "Title =" p3v6m(8fp1_0620.mljgrcfn_x.png "alt =" wkiom1ra1dzsd2beaabtddplgb0796.jpg "/> 650. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4C/9A/wKioL1RA1hPRuAYWAABaAVC1bXQ032.jpg "Title =" ym%015rf%e5s16%0_dv9%4e.png "style =" float: none; "alt =" wkiol1ra1hpruaywaabaavc1bxq032.jpg "/>
(Virtual Machine) (docker)
The figure shows the truth. It's no wonder the performance is much better if the hypervisor layer is missing!
Docker Composition
Let's take a look at the docker composition diagram.
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/4C/9B/wKioL1RA1sPz_3d1AAEh1WiKnpI281.jpg "Title =" 4s0000350000ovw'by000000000000vy@osor8.jpg "alt =" wkiol1ra1spz_3d1aaeh1wiknpi281.jpg "/>
Docker mainly consists of a container and an image.
Docker uses a file system called aufs (which requires Kernel support). This file system can be used to cascade and modify files. The bottom file system is read-only. If you need to modify files, aufs adds a writable layer, which is the container. Different iner can share the underlying read-only file system.
Container is a writable layer. You can use the dock commit to convert your container into a new read-only image.
Docker Installation
Environment: centos 6.5 x86_64 (centos7 comes from the docker software package by default)
[[Email protected] ~] # Rpm-uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel # Install the epel source [[email protected] ~] # Yum install docker-io # Install the docker Software Package [[email protected] ~] # Service docker start # Start the docker service [[email protected] ~] # Chkconfig docker on # Start the docker service on startup
Create a docker Image
There are many kinds of docker images, you can see the official introduction to https://docs.docker.com/articles/baseimages/
Here I use febootstrap (in the epel source) to create a docker image for centos 6.5 that can be SSH
Yum install febootstrap # Install febootstrap package febootstrap-I bash-I wget-I Yum-I iputils-I iproute-I man-I vim-minimal-I openssh-server-I openssh- clients centos6.5 centos6.5-image https://mirrors.ustc.edu.cn/centos/6.5/ OS /x86_64/ # install the required software package, centos6.5-image is the centos image folder. If you have ever played chroot, you should understand this CD centos6.5-image/& tar-C. | docker import-centos6.5-base # create a docker image [[email protected] ~] # Docker images # view the docker image repository tag image ID created virtual sizecentos6.5-base latest 3f9c6605aa3b 6 days ago 311.2 MB # create a docker image that supports SSH, it is recommended that the installation package use dockfile to define [[email protected] ~] # Vim dockerfile # compile dockfile # dockerfilefrom centos6.5-base # define the basic image maintainer ICE <[email protected]> # Run ssh-keygen-Q-n ""-t dsa-F /etc/ssh/ssh_host_dsa_key # Run the Shell Command run ssh-keygen-Q-n ""-t rsa-F/etc/ssh/ssh_host_rsa_keyrun sed-ir's /(. * pam_loginuid.so) // # \ 1/G'/etc/PAM. d/sshd run mkdir-P/root /. SSH & chown root. root/root & chmod 700/root /. SSH expose 22 # expose port 22 O 'root: 99cloud' | chpasswd # configure the root password env Lang en_US.UTF-8 # configure the environment variable env lc_all en_US.UTF-8CMD/usr/sbin/sshd-D # cmd indicates that the subsequent command is not run when building the image, run only during instantiation # End [[email protected] ~] # Ls/root/dockerfile # Check the dockfile path here./root/dockerfile [[email protected] ~] # Docker build-T centos6.5-ssh/root/# The Directory next to the dockfile [[email protected] ~] # Docker images # view docker image repository tag image ID created virtual sizecentos6.5-ssh latest 5009964eb87d 6 days ago 311.3 mbcentos6.5-base latest limit 6 days ago 311.2 MB [[email protected] ~] # Docker run-D-P 127.0.0.1: 2222: 22 centos6.5-ssh #-P ing port 22 of the docker instance to the local port 2222. If the-P option is not added, A port is randomly selected for ing.
More detailed dockerfile introduction https://docs.docker.com/reference/builder/
Reference
Http://my.oschina.net/feedao/blog/223795
Http://failshell.io/docker/building-a-centos-docker-base-image/
This article is from the "the-way-to-cloud" blog, please be sure to keep this source http://iceyao.blog.51cto.com/9426658/1565235
Getting started with docker