docker& Mirroring

Source: Internet
Author: User
Tags commit json docker hub

I want to make a mirror of the ethereum private chain, see the relevant information, and finally feel the need to understand the basic principles of Docker, perhaps the subsequent operation will be more smooth

https://capgemini.github.io/blockchain/ethereum-docker-compose/

Docker needs to have a corresponding mirror locally before running the container, and if the mirror does not exist locally, Docker will download it from the mirrored repository (by default, the warehouse in the Docker Hub Public Registry server).
The following main contents are:
**1 from the warehouse to obtain the mirror;
2 Manage mirroring on the local host;
3 describes the fundamentals of mirroring implementations. **

You can use the Docker pull command to get the required mirrors from the warehouse.
The following example downloads an Ubuntu 12.04 operating system image from the Docker Hub repository.

$  sudo    docker  pull    ubuntu:12.04 pulling    repository  ubuntu ab8e2728644c:    Pulling Dependent   layers 511136ea3c5a:    Download complete    5f0ffaa9455e:  Download    Complete A300658979be:  Download complete    904483ae0c30:  Download complete    ffdaafd1ca50:  Download Complete    d047ae21eeaf:  Download Complete    

During the download process, each layer of information that gets the image is output.
The command is actually equivalent to

    $  sudo    docker  pull    registry.hub.docker.com/ubuntu:12.04    

command, which is to download the image labeled 12.04 from the Ubuntu repository in the registry server registry.hub.docker.com.
Sometimes the official warehouse registration server download is slow and can be downloaded from other warehouses. You need to specify the full warehouse registration server address when downloading from another warehouse. For example

$  sudo    docker  pull    dl.dockerpool.com:5000/ubuntu:12.04 pulling Dl.dockerpool.com:5000/ubuntu Ab8e2728644c:pulling dependent   layers 511136ea3c5a:    Download complete    5f0ffaa9455e:  Download    Complete a300658979be:  Download complete    904483ae0c30:  Download complete    ffdaafd1ca50:  Download complete    d047ae21eeaf:  Download    Complete

Once you're done, you can use the image at any time, such as creating a container to run the Bash app.

$  sudo    docker  run-t-i  ubuntu:12.04    /bin/bash root@fe7fc4bd8fc9:/#
use      Docker  Images  
Displays the image that is already existing locally.
$  sudo    docker  images REPOSITORY                           TAG                     IMAGE   ID                      CREATED                     VIRTUAL SIZE ubuntu                                         12.04               74fe38d11401        4   weeks   ago     209.6   MB ubuntu                                           precise     74fe38d11401        4   weeks   ago     209.6   MB ubuntu                                           14.04               99ec81b80c55        4   weeks   ago     266 mb Ubuntu                                           latest          99ec81b80c55        4   weeks   ago     266 MB Ubuntu                                           trusty          99ec81b80c55        4   weeks   ago     266 MB ...

In the listing information, you can see several field information
from which warehouse, such as the Ubuntu image tag, such as 14.04 its ID number (unique) Create Time mirror size
Where the image ID uniquely identifies the mirror, notice that ubuntu:14.04 and ubuntu:trusty have the same mirror ID, which means they are actually the same mirror.

Tag     information is used to mark different images from the same warehouse. For       example      , there are multiple mirrors in the Ubuntu repository, which     can be differentiated by TAG     information, such as       10.04   ,   12.04   ,   12.10   ,   13.04   ,   14.04       and so on. For example, the following command specifies        that a container be started using a mirrored ubuntu:14.04.
$  sudo    docker  run-t-i  ubuntu:14.04    /bin/bash

If you do not specify a specific tag, the latest tag information is used by default.
Creating Mirrors

There are many ways to create an image, and users can obtain an existing image from the Docker Hub and update it, or create one with a local file system.
Modify an existing mirror

Start the container with the downloaded image first.

$  sudo    docker  run-t-i  training/sinatra    /bin/bash root@0b2616b0e5a8:/#

Note: Remember the ID of the container and use it later.
Add JSON and gem two apps to a container.

root@0b2616b0e5a8:/#    gem Install JSON

When this is over, we use Exit to exit, and now our container has been changed by us, using the Docker commit command to submit the updated copy.

$  sudo    Docker  Commit-  m  "Added  json gem"-a  "Docker Newbee" 0b2616b0e5a8    Ouruser/sinatra:v2 4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c

Where-M to specify the description of the submission, as we use the version Control tool;-A can specify updated user information, followed by the ID of the container used to create the mirror, and finally specify the warehouse name and tag information for the target image. The ID information for this image is returned when the creation is successful.
Use Docker images to view the newly created image.

$  sudo    docker  images REPOSITORY                                       TAG                 IMAGE   ID                          CREATED                         VIRTUAL SIZE Training/sinatra               Latest      5bc342fa0b91  hours   ago     446.7   MB Ouruser/sinatra                  v2                      3c59e02ddd1a  hours   ago     446.7   MB ouruser/sinatra                  latest      5db5f8471261  hours   ago     446.7   MB

After that, you can use the new mirror to start the container

$  sudo    docker  run-t-i  ouruser/sinatra:v2  /bin/bash root@78e82f680994:/#

using Dockerfile to create mirrors

Using Docker commit to extend an image is simple, but not easy to share in one team. We can use the Docker build to create a new image. To do this, you first need to create a Dockerfile that contains instructions on how to create the mirror.

Create a new directory and a Dockerfile

$  mkdir   Sinatra 
$  cd  Sinatra 
$  Touch   Dockerfile

Each instruction in the Dockerfile creates a layer of mirroring, for example:

#This   is  a   comment
from    ubuntu:14.04 
run apt-get-qq update
run apt-get-qqy    install ruby    ruby-dev
RUN gem install Sinatra

Dockerfile the basic syntax is
Use # to annotate the from instruction to tell Docker which image to use as the basis followed by the maintainer's information the instructions at the beginning of the run are running in the creation, such as installing a package, where you use Apt-get to install some software

You can use the Docker build to generate the image after writing the Dockerfile.

$ sudo docker build-t= "Ouruser/sinatra:v2". 
Uploading context 2.56 KB uploading context Step 0:from ubuntu:14.04---> 99ec81b80c55 Step 1:maintainer Newbee <newbee@docker.com>---> Running in 7c5664a8a0c1---> 2fa8ca4e2  A13 removing intermediate container 7c5664a8a0c1 Step 2:run apt-get-qq Update---> Running in  b07cc3fb4256---> 50d21070ec0c removing Intermediate container b07cc3fb4256 Step 3:run apt-get -qqy install ruby Ruby-dev---> Running in a5b038dd127e Selecting previously unselected package Liba San0:amd64. (Reading database ... 11518 files and directories currently installed.) Preparing to unpack .../libasan0_4.8.2-19ubuntu1_amd64.deb ... 
Setting up Ruby (1:1.9.3.4) ...
Setting up ruby1.9.1 (1.9.3.484-2UBUNTU1) ... Processing triggers for Libc-bin (2.19-0UBUNTU6) ...---> 2acb20f17878 
RUN gem install Sinatra---> Running in 5e9d0065c1f7.   . .    Successfully installed rack-protection-1.5.3 successfully installed sinatra-1.4.5 4 gems installed--->
 324104CDE6AD successfully built 324104CDE6AD

Where the-t flag is added to the tag to specify the user information for the new mirror. "." is the path (current directory) where the Dockerfile is located, or it can be replaced by a specific Dockerfile path.

You can see that the build process is performing an action. The first thing it needs to do is upload this Dockerfile content, because all the operations are based on Dockerfile. Then, the instructions in the dockfile are executed by one line. Each step creates a new container, executes the instructions in the container, and submits the changes (as in the case of the Docker commit described earlier). When all instructions have been executed, the final mirror ID is returned. All the containers produced by the intermediate steps are deleted and cleaned up.
* Note that an image cannot exceed 127 levels
In addition, you can use the ADD command to copy the local file to the mirror, open the port externally with the EXPOSE command, and use the CMD command to describe the program that is running after the container starts. For example

#   put my  local   Web site    in  myapp   folder  to  /var/www 
ADD myApp   /var/www 
#   Expose  httpd   Port expose 
#   the command to  run 
CMD ["/usr/sbin/ Apachectl ","-D ",   " FOREGROUND "]

You can now start a container with the newly created image.

$  sudo    docker  run-t-i  ouruser/sinatra:v2  /bin/bash root@8196968dac35:/#

You can also use the Docker tag command to modify the label of the Mirror.

$  sudo    docker  tag 5db5f8471261    ouruser/sinatra:devel
$  sudo    docker  images  Ouruser/sinatra REPOSITORY  
REPOSITORY                                      TAG                 IMAGE   ID                      CREATED                             VIRTUAL SIZE ouruser/ Sinatra                    latest      5db5f8471261  hours   ago         446.7 MB Ouruser/sinatra                  devel           5db5f8471261  hours   ago         446.7   MB ouruser/sinatra                  v2                      5db5f8471261  hours   ago         446.7   MB

Import from local file system
To import a mirror from the local file system, you can create it using the template for OpenVZ (the Pioneer Technology for container virtualization): The OpenVZ template download address is templates.
For example, a ubuntu-14.04 image is downloaded first and then imported using the following command:

sudo    cat ubuntu-14.04-x86_64-minimal.tar.gz      |docker import  -   ubuntu:14.04

Then view the newly imported image.

Docker  Images      
REPOSITORY                                      TAG                                                                 IMAGE   ID                                              CREATED                                                 VIRTUAL SIZE ubuntu                                                     14.04                                                           05ac7c0b9383  seconds ago                     215.5   MB

Upload Image
The Docker push command allows the user to upload the image they have created to the repository for sharing. For example, after the user has completed registration on the Docker Hub, they can push their own image into the repository.

$  sudo    docker  push    Ouruser/sinatra The 
push    refers  to  a   repository  [Ouruser/sinatra]   (len:   1) Sending  image   list 
pushing repository  Ouruser/sinatra (3  tags)

To save a mirror
If you want to export the image to a local file, you can use the Docker Save command.

$	sudo	docker	images REPOSITORY										TAG																	IMAGE	ID												CREATED													VIRTUAL	SIZE Ubuntu														14.04															c4ff7513909d								5	weeks	ago									225.4	MB ... $sudo   Docker  Save    -O  ubuntu_14.04.tar    ubuntu:14.04

load photographed like
You can use Docker load to import from an exported local file to a local mirror library, for example

$  sudo    docker  load    --input Ubuntu_14.04.tar

Or

$  sudo    docker  load    <   Ubuntu_14.04.tar

This imports the image and its associated metadata information (including tags, and so on).

Remove Local mirror
If you want to remove a local mirror, you can use the Docker RMI command. Note the Docker RM command removes the container.

$  sudo    Docker  rmi Training/sinatra 
untagged:   training/sinatra:latest 
Deleted:    5bc342fa0b91cabf65246837015197eecfa24b2213ed6a51a8974ae250fedd8d Deleted:   ed0fffdcdae5eb2c3a55549857a8be7fc8bc4241fb19ad714364cbfd7a56b22f Deleted:   5c58979d73ae448df5af1d8142436d81116187a7633082650549c52c3a2418f0

* Note: Use docker rm to delete all containers that depend on this image before deleting the image.

How the image is implemented
How the Docker image is implemented for incremental modification and maintenance. Each image is composed of many layers, and Docker uses union FS to combine these different layers into a single mirror.
Typically, the union FS has two uses, on the one hand can be implemented without the help of LVM, RAID multiple disk to the same directory, another more commonly used is to combine a read-only branch and a writable branch, the Live CD is based on this method allows users to be allowed on the basis of the mirror unchanged Perform some write operations on it. The containers that Docker builds on AUFS also take advantage of similar principles

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.