Docker Primer Summary

Source: Internet
Author: User
Tags docker ps

onboarding requires learning about Docker and documenting learning essays. Get a two-day general reading of Docker learning. Blogs are also considered to be migrating to Cnblogs.

Learn the link reference "Docker from getting started to practice" http://dockerpool.com/static/books/docker_practice/index.html

Source reference Https://github.com/tingfengainiaini/docker_practice, has been fork to my own GitHub

Also refer to Xu Xiao San blog http://www.cnblogs.com/openxxs/p/4634855.html

1, why use Docker

Docker is an open source project that was born in early 2013 and was originally an amateur project within the DotCloud company. It is based on Google's launch of the Go language implementation. The project later joined the Linux Foundation and complied with the Apache 2.0 protocol, and the project code was maintained on GitHub.

2, installation

The Ubuntu 14.04 version of the system has its own Docker package, which can be installed directly.

$ Wget-qo-https://get.docker.com/| sh

Test the status of Docker

$ Service Docker Status

Start Docker and test for a Hello-world

$ service Docker start

$ sudo docker run Hello-world

3, Three concepts

There are three concepts in the life cycle of Docker

    • Image (Image)
    • Container (Container)
    • Warehouse (Repository)

A mirror can contain a system, the system can be specifically customized requirements, mirroring for ease of migration. The container is created from the mirror. A container is a running instance created from a mirror. It can be started, started, stopped, deleted. Each container is a mutually isolated, secure platform. You can think of a container as a simple version of the Linux environment (including root user rights, process space, user space, and network space) and the applications running in it. Warehouses are places where images are stored. Note the difference between registering a warehouse server and a warehouse.

* Note: The image is read-only and the container creates a writable layer at the top level when it is started.

4,images Mirroring

$ sudo docker pull ubuntu:12.04

This defaults to getting a 12.04 version of Ubuntu from the Docker hub, the URL is registry.hub.docker.com

$ sudo docker run-t-i Ubuntu:12.04/bin/bash

Run bash in the ubuntu12.04 that you just downloaded. View Catalog discovery is a good concise version of the castration, a total of only 134M.

-tOption lets Docker assign a pseudo terminal (Pseudo-tty) and bind to the container's standard input, -i keeping the container's standard input open. Learn how to create mirrors and modify mirrors later.

When used docker run to create a container, the standard operations that Docker runs in the background include:

    • Checks if there is a specified image locally and does not exist to download from the public repository
    • Create and start a container with mirroring
    • Assign a file system and mount a layer of read-write layers outside the mirrored layer
    • Bridging a virtual interface into a container from the bridge interface configured by the host host
    • Configure an IP address from the address pool to the container
    • Executing user-specified applications
    • Container is terminated when execution is complete
5, Image Management

Save image $ sudo docker save-o Ubuntu_14.04.tar ubuntu:14.04

Import from local $ sudo cat ubuntu***.tar.gz |docker import-ubuntu:14.042

Upload image sudo docker push wx/tingfengaini here it is important to note that the mirror name of push must be formatted as <user>/imagename.

Upload the image you created to the repository to share. For example, after the user has completed registration on the Docker Hub, they can push their own image into the repository.

$ docker RM removes the container, and the Docker RMI removes the mirror. Remove all containers that depend on the image before removing the mirror, or-force delete

$ sudo docker ps-a. View the containers that are running;-A will list all the container information that has been run, and the-l parameter lists the container information that was last run.

For example, the following command outputs a "Hello world" and then terminates the container.

$ sudo docker run ubuntu:14.04 /bin/echo ‘Hello world‘Hello world

6,dockerfile

Common commands:

From <image>:<tag> dockerfile First command

Maintainer <name>

RUN <cmd> equivalent to/bin/sh-c;run ["Executable", "param1", "param2"] equivalent to exec

CMD container is executed at startup, only one valid, as in the above dockerfile only CMD ["/bin/ls", "-a"] valid and Cmd/bin/bash invalid

EXPOSE <port> containers exposed to the outside port number

ENV <key> <value> Specify environment variables

Add <src> <dest> Copy Local directory (relative path relative to dockerfile) or network directory or tar file to the container's specified directory; copy is similar but only local directory can be copied

EntryPoint container starts and executes, only one valid

VOLUME ["/data"] creates a mount point that can be mounted from a local host or other container

User daemon Specifies the username or UID when the container is run

Workdir Workdir Specify the working directory for subsequent naming

Onbuild [The instructions listed above can] the image as the underlying image of the other newly created image, the instruction executed is equivalent to the from after the execution of the onbuild specified instruction

The test commands are as follows:

$ sudo docker build-t= "Wx/tingfengaini".

Test the image and find a in USR. Can be viewed with VI, found that the same source of content files.

7, mirror implementation principle (not read)

How does a Docker image implement 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.

In general, 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 a read-only branch and a writable branch of the union together, Live CD It is based on this approach that allows the user to perform some write operations on a mirror-invariant basis. The containers that Docker builds on AUFS also take advantage of similar principles.

This paragraph is not how to understand, probably meant to be multi-tier files using union FS combined, a directory to mount multiple disk.

8, Container 8.1 start

Start a container using mirroring (the core is the application):

$ sudo docker run Ubuntu:14.04'helloworld'Hello World
$ sudo docker run-t-i ubuntu:14.04 /bin/bash[email protected]:/#

Where the -t option allows Docker to assign a pseudo terminal (Pseudo-tty) and bind to the container's standard input, leave -i the container's standard input open.

Using the PS command to see how the application is running discovers that it only runs bash and the PS command for querying, saving resources. ----Real-light, lightweight virtualization.

8.2 Daemon running containers, entering containers, container termination

Having Docker containers run in the background in the form of a daemon (daemonized) can be done by adding -d parameters. Use the Docker PS command to view the containers that the daemon runs. Docker PS View is running container information.

" While true; does echo Hello world, sleep 1; done " 1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147

Docker logs ID view daemon container output

Docker attach or nsenter into the container. Please see http://dockerpool.com/static/books/docker_practice/container/enter.html for details.

Dockerstop ID terminates the container. Docker ps-a View all container information. Docker Start/restart Restart the container.

8.3 container import, export, delete

Docker Export exports

Docker import Imports, note the difference between the Docker load image file import. The difference between the two is that the container snapshot file discards all history and metadata information (that is, only the snapshot state of the container at that time), while the mirrored storage file will hold the full record and be larger in size. In addition, metadata information such as labels can be re-specified when importing from a container snapshot file.

Docker RM (-f) ID deleted

9, Warehouse

Docker Login Register Repository

Docker Search Find Warehouse

Docker pull Download

Docker projects can automatically synchronize mirroring with GitHub or bitbucket.

This is no longer specific to the study, like GitHub, can be public repositories can also be private warehouses.

10, data volume

A data volume is a special directory that can be used by one or more containers, bypassing UFS and providing many useful features:

    • Data volumes can be shared and reused between containers
    • Changes to the data volume will take effect immediately
    • Updates to the data volume do not affect mirroring
    • The volume will persist until no container is used

* The use of data volumes, similar to Linux under the directory or file mount.

sudo docker run-d-p-v/webapp wx/tingfengaini/bin/mkdir/app/a

Here, after trying to find this way to load a data volume into the container's/webapp directory, and execute mkdir/app/a new directory in the directory, but after the container exits, there is no such folder to enter the image (this is not understood here)

Hang a native directory as a data volume into the container:

sudo docker run-d-p-v/webapp:/app wx/tingfengaini/bin/mkdir/app/-d-p-v/webapp:/app wx/tingfengaini sudo /bin/touch/app/a.txt

It was later discovered that the Docker hub was originally training/webapp this image file! Hey. I've been trying to get a mirror with Python.

 

Docker Primer Summary

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.