Docker Practice --- install a basic image (1)

Source: Internet
Author: User
Tags docker ps ubuntu touch

I spent a few days on the official website and learned a little about docker. Prepare to build a company's development and testing environment, including Java and python.

Environment Introduction

First, describe my environment

2 physical servers (hereinafter referred to as hosts)

The configuration of host a is 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 Aug 8 11:40:18 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux[[email protected] ~]# 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 unavailable today. I will introduce it later.


To create a basic image, you must have the following features:
  • Use domestic software sources
  • Install process management tool supervisor to manage startup Processes
  • You can use the SSH service.
There are many ways to create a base image from a file system to create an image. The official recommendation is to directly create a base image from the pull repository on the official website, so here I choose to create a base image from the file system. For more information, see my other blog http://blog.csdn.net/smallfish1983/article/details/38555827.

The following uses ubuntu14.04 as an example to 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
Use docker images to check docker images.
Repository tag image ID created virtual size
Ubuntu base 05ac7c0b9383 17 seconds ago 215.5 mb. In this way, we have created a basic Ubuntu Image Based on the openvz template. (Although official images may be smaller than this one, some basic tools such as ping are not installed, which is not very convenient. We recommend openvz templates) you can use docker dockerfile to change the software source and install the supervisor service to complete the entire process. However, it is more convenient to manually enter the configuration, dockerfile is more suitable for sharing your creation process with others. Run docker run-t-I Ubuntu: base/bin/Bash to go to the virtual machine and edit apt software source VI/etc/APT/sources. list, delete the content, paste the 163 source in China
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

Execute apt-Get update and install the supervisor service.
apt-get supervisorcp supervisord.conf conf.d/cd conf.d/vi supervisord.conf 
Modify the file as follows:
; 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; (modify the Startup Mode of the software to non-daemon, otherwise, docker will directly exit during execution.) [include] files =/etc/Supervisor/CONF. d /*. conf [Program: sshd] command =/usr/sbin/sshd-D; (add an SSH service) <span style = "font-family: Arial; "> <span style =" font-size: 14px; line-Height: 26px; "> </span>

Configure the SSH service to create an SSH running directory
mkdir /var/run/sshd
Change the root password passwd VI/etc/ssh/sshd_config modify the following two parameters to allow 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       512 MB<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"></span></span>

Submit the change to the new image ubuntu. If the colon tag is not added, the default tag is latest. Now, a new directory is created.
mkdir ubuntu touch ubuntu/Dockerfilevi ubuntu/Dockerfile
Add 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 context to Docker daemon Step 0 : FROM ubuntu ---> 5c21b6cf7ab3Step 1 : EXPOSE  22 ---> Running in 00a75d649b65 ---> 0429a60c040dRemoving intermediate container 00a75d649b65Step 2 : CMD ["/usr/bin/supervisord"] ---> Running in 49d505f56418 ---> c5d51fba9226Removing intermediate container 49d505f56418Successfully built c5d51fba9226<span style="font-family:Arial;"><span style="font-size: 14px; line-height: 26px;"></span></span>

Let's look at images.
[[email protected] start]# docker imagesREPOSITORY                       TAG                 IMAGE ID            CREATED              VIRTUAL SIZEubuntu                           latest              c5d51fba9226        About a minute ago   512 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 created Ubuntu is replaced by a new image. If you want to delete the previous image, you must delete the container we just executed 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
docker rm  f3c8005aa252
docker rmi 66604abb62b1

Let's look at images.
[[email protected] start]# docker imagesREPOSITORY                       TAG                 IMAGE ID            CREATED              VIRTUAL SIZEubuntu                           latest              c5d51fba9226        About a minute ago   512 MB

Docker run-P 301: 22-d -- name test Ubuntu/usr/bin/supervisord
Then we can SSH to port 301.
Here, a basic Ubuntu image is created, and other services will be created based on this 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.