Docker is an advanced container engine based on LXC, which is open-source by PaaS provider dotCloud. The source code is hosted on Github, and is open-source based on go language and complies with Apache2.0 protocol. Docker is an open source application container engine, which is based on the Go language and complies with the Apache2.0 protocol. Docker allows developers to package their applications and dependencies into a lightweight, portable container that can then be distributed to any popular Linux machine, as well as virtualization. Containers are completely sandboxed, have no interfaces with each other (like iPhone apps), and most importantly, have very low performance overhead.

V understanding Docker

Docker has been very popular since 2013, whether from github’s code activity, Redhat’s inclusion of Docker support in RHEL6.5, or even Google’s Compute Engine that allows Docker to run on top of it.

1.0 the Docker architecture

Docker uses a client-server (C/S) architecture pattern that uses remote apis to manage and create Docker containers. Docker containers are created by Docker images. The relationship between containers and images is similar to that between objects and classes in object-oriented programming.

Pictures from the network, deleted.

Docker image (Images) Docker images are templates used to create Docker containers.
Docker Container (Container) A container is a single application or group of applications that run independently.
Docker Client Docker clients use the Docker API through the command line or other tools.Docs.docker.com/develop/sdk…Communicates with the Docker daemon.
Docker Host (Host) A physical or virtual machine for executing Docker daemons and containers.
The Docker warehouse (Registry) Docker repository is used to store images, which can be understood as code repository in code control. Docker Hub(hub.docker.com) provides a large set of mirrors for use.
Docker Machine Docker Machine is a command line tool to simplify the installation of Docker, through a simple command line can be installed on the corresponding platform Docker, such as VirtualBox, Digital Ocean, Microsoft Azure.

1.1 Docker features

Due to its lightweight virtualization characteristics based on LXC, the most obvious feature of Docker compared with KVM is fast startup and small resource consumption. So build isolated, standardized operating environments, lightweight PaaS(like Dokku), build automated testing and continuous integration environments, and anything that can scale horizontally (especially Web applications that need quick start and stop to deal with peaks and valleys).

  • To build a standardized runtime environment, most existing solutions are to run a set of Puppet/Chef on a baseOS, or an image file. The disadvantage of the former is that the former requires many prerequisites of the Base OS. The latter is almost impossible to change (because the file format of copy on Write is read only at runtime rootfs). And the latter file size, environment management and versioning itself is a problem.
  • The PaaS environment is self-evident, both in its design and in the dotCloud case as the environmental basis for PaaS products
  • Automated testing and continuous integration/deployment integrate well because of its standardized build method (Buildfile) and good REST API
  • Because LXC is lightweight, it can start quickly, and Docker can only load the changed parts of each Container, which consumes less resources and is faster and consumes less resources than virtualization solutions such as KVM in a stand-alone environment

1.2 Docker Application Scenarios

  • Automating the packaging and deployment of applications
  • Creation of Lightweight, private PAAS Environments
  • Automated Testing and Continuous integration/deployment
  • Deploying and scaling WebApps Deploying and Scaling Web Apps Deploying and Scaling Database and Backend Services

1.3 What exactly is a Docker?

Let’s take a simple example. Docker assumes that the delivery operation environment is like shipping, and the OS is like a freighter. Each software based on the OS is like a container, and users can freely assemble the operation environment through standardized means. Meanwhile, the contents of the container can be customized by users or manufactured by professionals. In this way, the delivery of a piece of software is a collection of standardized components. Like Lego bricks, the user only needs to select the appropriate combination of bricks and stamp his name on the top (the last standardized component is the user’s app). This is the prototype of The Docker-based PaaS product.

V Docker

Version 2.0 Detection

As mentioned above, Docker requires a CentOS kernel version higher than 3.10. Check the prerequisites on this page to verify that your CentOS version supports Docker.

Check your current kernel version with the uname -r command

2.1 installation docker

The Docker package and dependencies are included with the default centos-extras software source: yum -y install Docker

2.2 Starting the Docker Service

Docker cannot be started using service docker start or systemctl start docker. Error message: Job for docker.service failed because the control process exited with error code. See “systemctl status docker.service” And “journalctl-xe” for details. The diagram below:

So I searched the Internet for all kinds of similar errors, tried to shut down the firewall, shut down Selinux, reinstall the system, and so on.

Disable selinux(vim /etc/sysconfig/docker) in docker. – selinux-enabled=false.

Full configuration after update: OPTIONS=’–selinux-enabled=false –log-driver=journald –signature-verification=false’

2.3 Test Run Hello-world

docker run hello-world

Docker run helloworld error: docker run helloworld

container_linux.go:235: starting container process caused "process_linux.go:258: applying cgroup configuration for process caused \"Cannot set property TasksAccounting, or unknown property.\""
/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "process_linux.go:258: applying cgroup configuration for process caused \"Cannot set property TasksAccounting, or unknown property.\"".
Copy the code

Solution: The main cause is the compatibility problem of the centos system version. If you update the system, the problem can be solved.

yum update

Docker run hello-world

2.4 Modifying an Image Source

The default source of Docker is foreign official source with slow download speed, so it can be changed to domestic source.

# vi /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
service docker restart
Copy the code

Domestic Ali and netease can be, or directly use the official -> domestic.

2.5 Setting Docker to automatically start upon startup

systemctl enable docker

Docker has been successfully started, so far, Docker has been installed.

V Explore Hello World

3.0 docker hello world

You can use the Docker run command to run an application inside the container, such as printing Hello World.

docker run centos /bin/echo "Hello World"

Parameter analysis:

  • docker : binary execution file of Docker.
  • run : combined with the previous docker to run a container.
  • centos : Specifies the image to run. Docker first looks up the image from the localhost to see if it exists. If not, Docker downloads the public image from the image repository Docker Hub.
  • /bin/echo "Hello world" : Command executed in the started container

Create a new container with a centos image, run bin/echo “Hello world” in the container, and print the result.

3.1 Running interactive containers

Docker run -i -t centos /bin/bash docker run -i -t centos /bin/bash

Parameter analysis:

  • -t : Specifies a dummy terminal or terminal in the new container.
  • -i : allows you to interact with standard input (STDIN) inside the container.

At this point we have entered a centos system container. We try to run the cat /proc/version and ls commands in the container to view the version information of the current system and the list of files in the current directory, respectively

We can exit the container by running the exit command or using CTRL+D.

3.2 Starting containers (Background Mode)

Use docker run -d centos /bin/sh -c “while true; do echo hello world; sleep 1; The done” command creates a container that runs as a process

A2274d84c6e8025623a17d1262f1a65dfaa9ce982de94d2301f4c0fff049ed7e the long string is called container ID, is unique for each container, we can through container ID to view the corresponding container what had happened.

We need to confirm that the container is running, which can be checked by Docker PS

CONTAINER ID: indicates the ID of a CONTAINER. NAMES: automatically assigned container NAMES

Use the docker logs command inside the container to view the standard output docker logs a2274D84c6e8

3.3 Stopping a Container

We use the Docker stop command to stop the container

At this point, docker Hello World is done.

About the author: Focus on basic platform project development. If you have any questions or suggestions, please feel free to comment! Copyright notice: The copyright of this article belongs to the author and the blog garden, welcome to reprint, but without the consent of the author must retain this statement, and give the original text link in a prominent place on the page of the article. For the record: all comments and messages will be answered as soon as possible. You are welcome to correct your mistakes and make progress together. Or direct private message I support the blogger: if you think the article is helpful to you, you can click on the lower right corner of the article [recommendation]. Your encouragement is the author to adhere to the original and continuous writing of the biggest power! \