What is the Docker
Docker is an open source application container engine, based on the Go language and follow the open source protocol Apache2.0
Docker allows developers to package their applications and dependencies to a lightweight, portable container and then posted to any popular Linux machine, can be virtualized
The container is full use of the sandbox mechanism will not have any interface (similar to the iPhone app) between each other, more important is the performance overhead is very low container
Docker application scenarios
Automation package and publish Web applications.
Automated testing and continuous integration, release.
Deployment and tuning the database or other back-office applications in a service-oriented environment.
Recompile or extend an existing OpenShift or Cloud Foundry PaaS platform to build their own environment
Docker's advantage
Docker is one for the development, delivery and open platform for running applications by means of Docker, you can manage the same application to manage infrastructure. by using
Docker way to quickly deliver, test, and deploy code, you can greatly reduce the delay between writing code and run code in a production environment
The basic concept of Docker
1. Mirror
Operating system is divided into kernel and user space. For Linux, the kernel starts, it will mount the root
file system to provide user-space support. The Docker Mirror
(Image), the equivalent of a root
file system. Docker image is a special file system, except when needed to provide a container to run programs, libraries, resource
Exogenous, configuration files, etc., also contain a number of configuration parameters to prepare for the operation (such as anonymous volume, environment variables, user, etc.). Image does not contain any number of dynamic
According to its content will not be changed after the building.
2. container
Mirror ( Image
) and container ( Container
relations), like object-oriented programming design 类
and 实例
the same image is a static definition of container is a mirror image
Entity runtime. Container can be created, start, stop, delete, pause. The process is the essence of container, but in a different process and direct the implementation of a host, into the container
Cheng run in their own separate namespace . Therefore, the container can have its own root
file system, your network configuration, its own process space, even from
Space own user ID.
3. warehouse
Mirroring the build is finished, it can easily run on the current host, but if you need to use this image on another server, we need a centralized
Storage, distribution mirroring service, Docker Registry is one such service. A Docker Registry may comprise a plurality of warehouse ( Repository
);
Each repository may comprise a plurality of tags ( Tag
); each tag corresponds to a mirror. Typically, a warehouse will contain different versions of the same software image, and label it
It should be used in all versions of the software. We can <仓库名>:<标签>
format to specify which version of the software specifically a mirror. If you do not mark given
Sign, will be latest
used as the default label.
Ubuntu installation Docker
# WARNING: Do not configured directly using apt command to install the case Docker Docker APT source.
Uninstall the old version
Older versions of Docker called docker
or docker-engine
, use the following command to uninstall the old version:
$ sudo apt-get remove docker docker-engine docker.io
Use apt to install
Since the apt
source uses HTTPS to ensure that the process of downloading the software is not tampered with. Therefore, we first need to add software packages use the HTTPS transport and CA certificate
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
In view of the domestic network problems, it is strongly recommended to use domestic sources, official sources in comments please, to confirm the legitimacy of the downloaded package, you need to add the software source GPG
key
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 官方源 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
To source.list
add Docker source software
$ sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable
# 官方源
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Installation Docker CE
Update apt package cache, and install docker-ce
:
$ sudo apt-get update
$ sudo apt-get install docker-ce
The installation was successful, view the version docker
$ docker -v
Docker version 19.03.5, build 633a0ea838
Start Docker CE
$ sudo systemctl enable docker
$ sudo systemctl start docker
Establish docker User Group
By default, the docker
command uses the Unix socket and Docker engine traffic. The only root
users and docker
groups of users can access Docker engine
Unix socket. For security reasons, do not directly use the general Linux system root
users. Therefore, a better approach is to require the use docker
of user plus
The docker
user group
建立docker组: $ sudo groupadd docker
将当前用户加入docker组: $ sudo usermod -aG docker $USER
Set up a mirrored warehouse sources
The default warehouse is mirrored abroad, pulling the mirror is very slow, so in order to facilitate image capture, you can change the image source, is to add a configuration file
$ sudo vi /etc/docker/daemon.json
Add the following information:
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
Restart container services, to take effect
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
View mirror source if changes
$ docker info
Ubuntu installation Docker-compose
Compose Profile
Compose is a tool to define and run multiple applications for Docker containers. By Compose, you can use the YML file to configure the application needs
All services. Then, use a command, you can create a configuration file from the YML and start all services
Binary packages installed compose
Use the following link to download and install
$ sudo curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
1.24.0 version compose, and will be free to modify and select
If the above command does not also perform (Note: Only for the Linux-x86_64 users)
$ sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-Linux-x86_64 -o /usr/local/bin/docker-compose
Install successfully modified binary permissions, add execute permissions x
$ sudo chmod +x /usr/local/bin/docker-compose
View docker-compose version
$ docker-compose -v
docker docker-compose and other installers
Use a script to automatically install docker-ce
In a test or development environment Docker official order to simplify the installation process and provides a set of easy installation scripts, you can use this script to install the Ubuntu system,
Also can --mirror
be installed using a domestic source options:
$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
# $ sudo sh get-docker.sh --mirror AzureChinaCloud
After executing this command, the script will automatically remove all the preparation work, and the Docker CE stable (stable) version installed in the system
pip install compose
Note: The x86_64
architecture of Linux is recommended to download binary packages installed in accordance with the method of the top, if your computer's architecture ARM
(for example, raspberry pie), then use
pip
installation. Compose in this way is as a Python application to install from source pip
The installation command:
$ sudo pip install -U docker-compose
Can be seen as similar to the output of the installation is successful
Collecting docker-compose
Downloading docker-compose-1.17.1.tar.gz (149kB): 149kB downloaded
...
Successfully installed docker-compose cached-property requests texttable websocket-client docker-py dockerpty six enum34 backports.ssl-match-hostname ipaddress
Reference: Docker- from entry to practice Docker- rookie tutorial Zhang Yan Cheng of Docker