1. Introduction to docker
Docker is an open source application container engine, which allows developers to package their applications and dependent packages into a portable container, and then publish them to any popular Linux or Windows operating system machine. It can also realize virtualization. The container completely uses the sandbox mechanism without any interface with each other.
A complete Docker consists of the following parts:
DockerClient client
Docker Daemon
Docker Image mirroring
DockerContainer container [2]
origin
Docker is an LXC based advanced container engine open source by dotCloud, a PaaS provider. The source code is hosted on Github, based on go language and complies with Apache 2.0 0 protocol is open source.
Docker has been very popular since 2013, whether from the code activity on github or Redhat on rhel6 5 integrates support for docker, and even Google's Compute Engine supports docker to run on it.
The commercial success of an open source software largely depends on three things - a successful user case, an active community and a good story. The PaaS products of dotCloud house are built on docker, which is maintained for a long time and has a large number of users. The community is also very active. Let's take a look at the story of docker.
Complex environment management - from various OS to various middleware to various app s, a product can succeed. As a developer, there are too many things to care about and difficult to manage. This problem needs to be faced in almost all modern IT related industries.
The advent of cloud computing era - the success of AWS has guided developers to transfer applications to cloud and solved the problem of hardware management. However, problems related to middleware still exist (so openstack HEAT and AWS cloudformation strive to solve this problem). Developers' thinking changes provide the possibility.
Changes in virtualization means - in the cloud era, standard hardware is used to reduce costs, virtualization means are used to meet the needs of users on demand and ensure availability and isolation. However, both KVM and Xen are wasting resources in docker's view, because users need an efficient operating environment rather than OS. Guestos is both a waste of resources and difficult to manage, and the more lightweight LXC is more flexible and fast
LXC mobility - LXC already exists in the kernel of linux 2.6, but it was not designed for cloud computing at the beginning. Due to the lack of standardized description means and container portability, the built environment is difficult to migrate and standardize management (compared with the concepts of image and snapshot such as KVM). Docker made substantial innovations on this issue. This is the most unique part of docker.
2. Install docker to centos7 five
Operating system requirements
To install the Docker engine, you need a maintained version of CentOS 7 or 8. Archive version is not supported or tested.
The repository must be enabled. By default, this repository is enabled, but if it is disabled, you need to re enable it. centos-extras
Storage drivers are recommended.
3 uninstall old version
The old version of Docker is called or If these items are already installed, uninstall them with the associated dependencies. dockerdocker-engine
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
It doesn't matter if you report that these packages are not installed. yum
What will be retained, including images, containers, volumes, and networks. The Docker engine package is now called/ var/lib/docker/docker-ce
Installation method
You can install Docker engine in different ways as needed:
Set up repository
Install software packages (provide utilities) and set up a stable repository.
sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
4. Install Docker engine
Install the latest version of Docker engine and containerd, or go to the next step to install a specific version:
sudo yum install docker-ce docker-ce-cli containerd.io
5 start Docker.
sudo systemctl start docker
Verify that the Docker engine is installed correctly by running the image. hello-world
sudo docker run hello-world
This command downloads the test image and runs it in the container. When the container runs, it prints a message and exits.
Start Docker.
sudo systemctl start docker
Verify that the Docker engine is installed correctly by running the image. hello-world
sudo docker run hello-world
This command downloads the test image and runs it in the container. When the container runs, it prints a message and exits.
6 unloading
Uninstall Docker engine
Uninstall Docker engine, CLI, and container package:
sudo yum remove docker-ce docker-ce-cli containerd.io
Images, containers, volumes, or custom profiles on the host are not automatically deleted. Delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd
You must manually delete any edited profiles.
7 docker command
1. docker history : View the creation history of the specified mirror. --restart=always grammar docker history [OPTIONS] IMAGE OPTIONS explain: • -H :Prints the image size and date in a readable format. The default is true; • --no-trunc :Display complete submission records; • -q :List submission records only ID. • --------------------------Enter the inside of the container------------------------------------------------------------------ docker exec-it webserv /bin/bash Show that this is into docker webserv This image is. echo"Hello Docker">/usr/share/nginx/html/index.html ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1. docker rmi : Delete one or more local mirrors. grammar docker rmi [OPTIONS] IMAGE [IMAGE...] OPTIONS explain: • -f :Forced deletion; • --no-prune :The process image that does not remove the image is removed by default; • ------------------------------------------------------------------------------------------------------- 1. docker build : use Dockerfile Create a mirror. grammar docker build [OPTIONS] PATH | URL | - OPTIONS explain: • --build-arg=[] :Set the variables when creating the image; • --cpu-shares :set up cpu Use weights; • --cpu-period :limit CPU CFS Cycle; • --cpu-quota :limit CPU CFS Quotas; • --cpuset-cpus :Specify the used CPU id; • --cpuset-mems :Specifies the memory used id; • --disable-content-trust :Ignore verification and enable by default; • -f :Specify the to use Dockerfile route; • --force-rm :Delete intermediate containers in the process of setting mirroring; • --isolation :Use container isolation technology; • --label=[] :Set the metadata used by the image; • -m :Set the maximum memory value; • --memory-swap :set up Swap The maximum value for is memory+swap,"-1"Indicates unlimited swap; • --no-cache :The process of creating an image does not use cache; • --pull :Try to update the new version of the image; • -q :Quiet mode. Only the image is output after success ID; • --rm :Delete the intermediate container after setting the image successfully; • --shm-size :set up/dev/shm The default value is 64 M; • --ulimit :Ulimit to configure. example Use of current directory Dockerfile Create a mirror. docker build -t w3cschool/ubuntu:v1 . use URL github.com/creack/docker-firefox of Dockerfile Create a mirror. docker build github.com/creack/docker-firefox ------------------------------------------------------------------------------------------------------------------ docker save : Save the specified image as tar Archive files. grammar docker save [OPTIONS] IMAGE [IMAGE...] OPTIONS explain: • -o :File to export to. example Mirror w3cschool/ubuntu:v3 generate my_ubuntu_v3.tar file w3cschool@w3cschool:~$ docker save -o my_ubuntu_v3.tar w3cschool/ubuntu:v3 w3cschool@w3cschool:~$ ll my_ubuntu_v3.tar -rw------- 1 youj youj 142102016 Jul 11 01:37 my_ubuntu_v3.ta Command to enter the inside of the container docker exec -it 98a658d89b13 bash dokcer ps -a Query running container docker exec -it container ID /bin/bash Enter container exit Exit container
docker my commonly used startup commands
Docker start-up nginx docker run -d -p 80:80 nginx:latest Parameter Description: run Start a mirror -d Let the container run in the background -p Specify the port mapping. Port 80 of the host is mapped to port 80 of the container --restart Restart mode, setting always,Every start docker Will start nginx Container. docker exec -it nginx container ID /bin/bash # Enter container
Docker start-up redis docker run --name redis -p 6379:6379 -d --restart=always redis:latest redis-server --appendonly yes --requirepass "12345678"
# Start the docker service of the computer systemctl start docker # Start the relevant docker View all docker docker container ls -a #Start the relevant docker according to the docker id docker start dockerid docker stop dockerid • 1: Linux lower docker Set startup and self startup • sudo systemctl enable docker • 2: Enter the interactive mode of the container( docker (internal command to install the container) • Container name is redis Or container id • Enter the interactive mode of the container docker exec -it redis /bin/bash • The inside of the container is complete Linux Directory structure of • Startup self startup docker update redis --restart=always