Soak up the official website for a few days and the right Docker has a better understanding. Ready to start building a company's development and testing environment, including Java, Python.
Environment Introduction
First of all, explain my environment.
2 physical server (hereafter referred to as host)
Host a configuration, as follows:
[Email protected] ~]# lsb_release-alsb Version: : base-4.0-amd64:base-4.0-noarch:core-4.0-amd64: Core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarchdistributor ID: Centosdescription: CentOS release 6.5 (Final) Release: 6.5Codename: final[[email protected] ~]# uname- Alinux opnvz 3.10.52-1.el6.elrepo.x86_64 #1 SMP Fri 8 11:40:18 EDT x86_64 x86_64 x86_64 gnu/linux[[email protecte D] ~]# Docker versionclient version:1.0.0client API version:1.12go version (client): Go1.2.2git commit (client): 63fe64c /1.0.0server version:1.0.0server API version:1.12go version (server): Go1.2.2git commit (server): 63fe64c/1.0.0
Host B is not available today, and we'll introduce it later.
Target creates a base image that requires the following features:
- Use of domestic software sources
- Install the Process Management tool supervisor manage the startup process
- Ability to use SSH services
Installation steps creating a base image from a file system there are many ways to create a mirror, and the official recommendation is to pull one directly from the official website, but because the website is more powerful than the wall. So here I choose to create a base image from the file system. Specific method See my other piece of blog http://blog.csdn.net/smallfish1983/article/details/38555827
Here take ubuntu14.04 as an example. Download a ubuntu14.04 template from OpenVZ
wget http://download.openvz.org/template/precreated/ubuntu-14.04-x86_64.tar.gz
Cat ubuntu-14.04-x86_64-minimal.tar.gz |docker Import-ubuntu:base
Then use Docker images to see: Docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Ubuntu base 05ac7c0b9383 seconds ago 215.5 MB So we've built an Ubuntu base image based on the OpenVZ template. (Although the official image may be smaller than this, some basic such as ping This tool is not installed, not very convenient, recommended OpenVZ template) Change the software source, install the Supervisor service can use Docker Dockerfile to complete the process, Just a person to feel or their own manual in the configuration after the more convenient. Dockerfile is more suitable for sharing your creation process to others.
Here we run Docker run-t-I ubuntu:base/bin/bash into the virtual machine edit apt software source vi/etc/apt/sources.list, remove the content inside, paste on the source of domestic 163
Deb Http://mirrors.163.com/ubuntu/trusty main restricted universe Multiversedeb http://mirrors.163.com/ubuntu/ Trusty-security main restricted universe multiversedeb http://mirrors.163.com/ubuntu/trusty-updates main restricted Universe Multiversedeb http://mirrors.163.com/ubuntu/trusty-proposed main restricted universe Multiversedeb/HTTP Mirrors.163.com/ubuntu/trusty-backports main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/ Trusty main restricted universe multiversedeb-src http://mirrors.163.com/ubuntu/trusty-security main restricted Universe multiversedeb-src http://mirrors.163.com/ubuntu/trusty-updates main restricted universe MULTIVERSEDEB-SRC http://mirrors.163.com/ubuntu/trusty-proposed main restricted universe multiversedeb-src http://mirrors.163.com/ Ubuntu/trusty-backports Main restricted Universe multiverse
Run the Apt-get update update and then install the Supervisor service
Change the file such as the following:
; Supervisor Config File[unix_http_server]file=/var/run/supervisor.sock ; (The path to the socket file) chmod=0700 ; sockef file mode (default 0700) [supervisord]logfile=/var/log/supervisor/ Supervisord.log; (Main log File;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid; (Supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; (' AUTO ' child log dir, default $TEMP) Nodaemon=true . (Change the startup mode of the software to be non-daemon, or Docker will exit directly when it is running) [include]files =/etc/supervisor/conf.d/*.conf[program:sshd]command =/usr /sbin/sshd-d ; (Join the SSH service) <span style= "font-family:arial;" ><span style= "FONT-SIZE:14PX; line-height:26px; " ></span></span>
Configure the SSH service to create an execution folder for SSH
Mkdir/var/run/sshd
Change Rootpassword passwd vi/etc/ssh/sshd_config changes the following 2 participants consent to root login
Permitrootlogin Yes
Usepam No
Exit Docker
[Email protected]:/etc/supervisor/conf.d# exitexit[[email protected] start]# Docker commit F3c8 Ubuntu 5c21b6cf7ab3f60693f9b6746a5ec0d173fd484462b2eb0b23ecd2692b1aff6b[[email protected] start]# Docker ImagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL sizeubuntu latest 5c21b6cf7ab3 6 seconds ago Mb<span style= " font-family:arial; " ><span style= "FONT-SIZE:14PX; line-height:26px; " ></span></span>
submit the changes just now to the new image on Ubuntu. Assume that you do not add a colon tag. The default tag is latestCreate a new folder now
mkdir Ubuntu Touch Ubuntu/dockerfilevi ubuntu/dockerfile
Add for example the following content
From Ubuntuexpose 22CMD ["/usr/bin/supervisord"]<span style= "font-family:arial;" ><span style= "FONT-SIZE:14PX; line-height:26px; " ></span></span>
then create an image from this file
[[email protected] start]# Docker build-t Ubuntu ubuntu/sending build context to Docker daemon 2.56 kbsending build C Ontext to Docker daemon Step 0:from ubuntu---> 5c21b6cf7ab3step 1:expose $ ---> Running in 00a75d649b65-- 0429a60c040dremoving Intermediate container 00a75d649b65step 2:cmd ["/usr/bin/supervisord"]---> Running in 49d 505f56418---> c5d51fba9226removing intermediate container 49d505f56418successfully built C5d51fba9226<span Style= "font-family:arial;" ><span style= "FONT-SIZE:14PX; line-height:26px; " ></span></span>
and look at the images .
[[email protected] start]# Docker imagesrepository TAG IMAGE ID CREATED VIRTUAL sizeubuntu Latest c5d51fba9226 about a minute ago mb<none> <none> 66604abb62b1 38 Minutes ago 570.3 Mb<span style= "font-family:arial;" ><span style= "FONT-SIZE:14PX; line-height:26px; " ></span></span>
the Ubuntu you just created was replaced by the new image, and the previous image was assumed to be deleted. You have to delete the container that we just ran, and then delete the image
Docker Ps-a<span style= "font-family:arial;" ><span style= "FONT-SIZE:14PX; line-height:26px; " ></span></span>
find the container just now.
Docker RM f3c8005aa252
Docker RMI 66604ABB62B1
And look at the images.
[[email protected] start]# Docker imagesrepository TAG IMAGE ID CREATED VIRTUAL sizeubuntu Latest c5d51fba9226 about a minute ago mb
Docker run-p 301:22-d--name test Ubuntu/usr/bin/supervisord
and then we'll be able to ssh to 301port.
Here, foundation Ubuntu basic Image creation complete, this behind the image created on the basis of other services
Docker Real---Installation base image (i)