1. Overview of Docker containers
- Differentiate Docker container technology from VM virtual machine technology:
evernotecid://394EFE90-9CE0-4D65-A8CD-DFEC0DC8061E/appyinxiangcom/11359837/ENResource/p1872
Docker container technology [Container]: container virtualization technology
evernotecid://394EFE90-9CE0-4D65-A8CD-DFEC0DC8061E/appyinxiangcom/11359837/ENResource/p1873
VM Virtual Machine Technology: Traditional Virtualization Technology
evernotecid://394EFE90-9CE0-4D65-A8CD-DFEC0DC8061E/appyinxiangcom/11359837/ENResource/p1873
The main differences are:- [1] Containers provide process-based isolation, while virtual machines provide complete isolation of resources.
- [2] Virtual machines may take a minute to start, while containers may only take a second or less.
- [3] Containers use the kernel of the host operating system, while virtual machines use separate cores
- Benefits of containers
1.2.0 Containers
- Docker Container Release Version:
Docker CE (Community Edition): Free Open Source Version-Docker Engine
Docker EE (Enterprise): Commercial Charge Version-Docker Data Center - Docker container installation environment:
Public Cloud Environment: Install Docker based on Ali Cloud and Tencent Cloud Hosts
Private Cloud Environment: Install Docker based on an autonomous host environment - Basic components of the Docker platform:
evernotecid://394EFE90-9CE0-4D65-A8CD-DFEC0DC8061E/appyinxiangcom/11359837/ENResource/p1874
The Docker platform is basically made up of three parts: - [1] Client: Users use Docker's tools (CLI, API, etc.) to build, upload mirrors, and issue commands to create and launch container Dockers
- [2] Host: Download mirror from Docker registry and start container Docker
- [3] Regisry: Docker Mirror Repository, which stores the images and provides them for analysis in subsequent articles that are uploaded and downloaded.
2.Docker container deployment and installation
Docker Container Deployment
View the Centos7 development environment: cat/etc/centos-release
[root@centos-amber ~]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core) [root@centos-amber ~]#
View the Centos7 kernel version: uname-a or cat/proc/version
[root@centos-amber ~]# uname -a Linux centos-amber 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux [root@centos-amber ~]#
Before adding the Docker Ali cloud yum source, you need to perform the basic component installation and uninstall the historical version:
Basic component installation: yum-y install GCC & yum-y install gcc-c++.
#gcc environment installation yum -y install gcc yum -y install gcc-c++
Uninstall historical version: yum-y remove docker docker-common docker-selinux docker-engine
[root@centos-amber ~]# yum -y remove docker docker-common docker-selinux docker-engine Loaded plugins: fastestmirror No Match for argument: docker No Match for argument: docker-common No Match for argument: docker-selinux No Match for argument: docker-engine No Packages marked for removal [root@centos-amber ~]#
Or remove the installed Docker
# Uninstall installed docker [root@centos-amber ~]# sudo yum remove docker \ > docker-client \ > docker-client-latest \ > docker-common \ > docker-latest \ > docker-latest-logrotate \ > docker-logrotate \ > docker-selinux \ > docker-engine-selinux \ > docker-engine Loaded plugins: fastestmirror No Match for argument: docker No Match for argument: docker-client No Match for argument: docker-client-latest No Match for argument: docker-common No Match for argument: docker-latest No Match for argument: docker-latest-logrotate No Match for argument: docker-logrotate No Match for argument: docker-selinux No Match for argument: docker-engine-selinux No Match for argument: docker-engine No Packages marked for removal [root@centos-amber ~]#
Ps: Docker deployment requires a 64-bit system with a kernel version of at least 3.10
2.0.2 Deployment Docker Add yum source: yum install epel-release-y && yum list
[root@centos-amber ~]# yum install epel-release –y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Package epel-release-7-11.noarch already installed and latest version Nothing to do [root@centos-amber ~]# [root@centos-amber ~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: base epel extras updates Cleaning up list of fastest mirrors [root@centos-amber ~]# yum list
2.1 Docker Container Installation
Configure Aliyun Docker Yum Source
- [1] Set up repository :
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
[root@centos-amber docker]# sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ............. [root@centos-amber docker]#
- [2] Use Aliyun Docker
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@centos-amber docker]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo Loaded plugins: fastestmirror adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo [root@centos-amber docker]#
Update Yum cache: sudo yum-y makecache fast
[root@centos-amber ~]# sudo yum makecache fast Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 5.3 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 (1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00 (2/2): docker-ce-stable/x86_64/primary_db | 32 kB 00:00:00 Metadata Cache Created [root@centos-amber ~]# sudo yum -y makecache fast Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 epel | 5.3 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 Metadata Cache Created [root@centos-amber ~]#
View the corresponding version: yum list docker-ce --showduplicates
[root@centos-amber docker]# yum list docker-ce --showduplicates Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile docker-ce-stable | 3.5 kB 00:00:00 (1/2): docker-ce-stable/x86_64/updateinfo | 55 B 00:00:00 (2/2): docker-ce-stable/x86_64/primary_db | 32 kB 00:00:00 Available Packages docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.03.3.ce-1.el7 docker-ce-stable docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.09.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 17.12.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable [root@centos-amber docker]#
2.1.3 Install the latest version of Docker: sudo yum install docker-ce
docker-ce-cli or yum install docker-io-y
[root@centos-amber docker]# sudo yum install docker-ce .............. Installed: docker-ce.x86_64 3:19.03.1-3.el7 Dependency Installed: audit-libs-python.x86_64 0:2.8.4-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.107-1.el7_6 containerd.io.x86_64 0:1.2.6-3.3.el7 docker-ce-cli.x86_64 1:19.03.1-3.el7 libcgroup.x86_64 0:0.41-20.el7 libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-29.el7_6.1 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7 Complete! [root@centos-amber docker]#
2.1.4 Start the Docker service:
# Start docker service systemctl enable docker systemctl start docker
Execution: systemctl enable docker allows startup
[root@centos-amber docker]# systemctl enable docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@centos-amber docker]#
Execute: systemctl start docker starts the Docker service
[root@centos-amber docker]# systemctl start docker [root@centos-amber docker]#
Basic commands:
systemctl enable docker # Allow startup
systemctl start docker #Run the Docker daemon
systemctl stop docker #Stop the Docker daemon
systemctl restart docker #Restart the Docker daemon
systemctl status docker #View the running status of Docker
2.1.5 Verify installation of Docker service information:
Execution: docker info view Docker service information
[root@centos-amber docker]# docker info Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.1 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-957.27.2.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.795GiB Name: centos-amber ID: TS7V:P2HE:MICX:JPN7:H5JU:PQX5:JWB3:4YSO:DM7X:RVBV:URME:64DZ Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false [root@centos-amber docker]#
Execution: docker version view version number
[root@centos-amber docker]# docker version Client: Docker Engine - Community Version: 19.03.1 API version: 1.40 Go version: go1.12.5 Git commit: 74b1e89 Built: Thu Jul 25 21:21:07 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.1 API version: 1.40 (minimum version 1.12) Go version: go1.12.5 Git commit: 74b1e89 Built: Thu Jul 25 21:19:36 2019 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.6 GitCommit: 894b81a4b802e4eb2a91d1ce216b8817763c29fb runc: Version: 1.0.0-rc8 GitCommit: 425e105d5a03fabd737a126ad93d62a9eeede87f docker-init: Version: 0.18.0 GitCommit: fec3683 [root@centos-amber docker]#
3. Docker Configure Ali Cloud Mirror Accelerator
Docker password: Docker 20190822
Ali Cloud Official Network Configuration:
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://j98vrcq8.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
Edit configuration file: vim/etc/docker/daemon.json
[root@centos-amber docker]#vim /etc/docker/daemon.json { "registry-mirrors": ["https://j98vrcq8.mirror.aliyuncs.com"] } [root@centos-amber docker]# sudo systemctl daemon-reload [root@centos-amber docker]# sudo systemctl restart docker [root@centos-amber docker]# [root@centos-amber docker]# docker info Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.1 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 894b81a4b802e4eb2a91d1ce216b8817763c29fb runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f init version: fec3683 Security Options: seccomp Profile: default Kernel Version: 3.10.0-957.27.2.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.795GiB Name: centos-amber ID: TS7V:P2HE:MICX:JPN7:H5JU:PQX5:JWB3:4YSO:DM7X:RVBV:URME:64DZ Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Registry Mirrors: https://j98vrcq8.mirror.aliyuncs.com/ Live Restore Enabled: false [root@centos-amber docker]#
4. Deployment and installation of Docker container basic components
Compose Component Deployment and Installation
Basic overview:
Docker Compose is a Docker tool used to define and run complex applications.
An application that uses Docker containers usually consists of multiple containers.
Using Docker Compose no longer requires shell scripts to start containers.(
Compose manages multiple Docker containers through one configuration file, where all containers are defined by services.Then use the docker-compose script to start, stop, and restart the application, the services in the application, and all the containers that depend on the service, which is ideal for scenarios where multiple containers are combined for development
How to install docker-compose:
- [1] Download docker-compose binary installation from github
Download the latest version of the docker-compose file:
sudo curl -L https://github.com/docker/compose/releases/download/1.25.0-rc2/docker-compose-uname -s-uname -m -o /usr/local/bin/docker-compose
[root@centos-amber ~]# sudo curl -L https://github.com/docker/compose/releases/download/1.25.0-rc2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 617 0 617 0 0 640 0 --:--:-- --:--:-- --:--:-- 640 3 16.1M 3 645k 0 0 1669 0 2:48:53 0:06:35 2:42:18 0 curl: (56) TCP connection reset by peer [root@centos-amber ~]#
Add Executable Rights: sudo Chmod +x/usr/local/bin/docker-compose
[root@centos-amber ~]# sudo chmod +x /usr/local/bin/docker-compose [root@centos-amber ~]#
Unload docker-compose execution: sudo rm/usr/local/bin/docker-compose
[root@centos-amber ~]# sudo rm /usr/local/bin/docker-compose [root@centos-amber ~]#
- [2] Install using the pip install command:
Installation method: sudo pip install docker-compose
sudo pip install docker-compose
Uninstall method: pip uninstall docker-compose
pip uninstall docker-compose
Two ways to verify installation results: docker-compose --version
[root@centos-amber ~]# docker-compose --version /usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn't match a supported version! RequestsDependencyWarning) docker-compose version 1.24.1, build 4667896 [root@centos-amber ~]#
Machine Component Deployment and Installation
Basic overview:
Docker Machine is a tool that allows you to install Docker Engine on a virtual host and manage the host using the docker-machine command.
How to install docker-compose:
curl -L https://github.com/docker/machine/releases/download/v0.16.1/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
Docker establishes network communication with the host:
Ps1: docker port mapping error
docker: Error response from daemon: driver failed programming external connectivity on endpoint mysql-master (1aac2f09e8d851518f8551308ccbe1e036454d5103bd99fba3f7b3870e3b21b4): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3307 -j DNAT --to-destination 172.17.0.4:3306 ! -i docker0: iptables: No chain/target/match by that name. (exit status 1)).
Solution:
- [1] Execution: pkill docker
- [2] iptables -t nat -F
- [3] ifconfig docker0 down
- [4] brctl delbr docker0
pkill docker && iptables -t nat -F && ifconfig docker0 down && brctl delbr docker0
ps2: linux brctl command not found
[root@centos-meteor ~]# brctl delbr docker0 -bash: brctl: command not found
Host installation: yum install bridge-utils
4. Summary of Docker container deployment and installation
The docker configuration is based on the Yum source of Ali Cloud:
- [1] Install the necessary system tools: sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- [2] Add software source information: sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- [3] Update and install Docker-CE: sudo Yum makecache fast sudo yum-y install docker-ce
sudo yum makecache fast sudo yum -y install docker-ce
- [4] Open Docker service: systemctl enable docker systemctl start docker
systemctl enable docker systemctl start docker
The docker deployment installation and basic commands use:
- [1] Docker deployment requires a 64-bit system with a kernel version of at least 3.10
- [2] Docker installation directory: var/lib/docker and/var/lib/docker-engine
- [3] Docker configuration directory: /etc/docker
Docker deployment portainer
docker run -ti -d --name portainer -p 9000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer
Copyright Notice: This is an original blogger article, which follows the relevant copyright agreement. If you want to reproduce or share it, please attach a link to the source of the original text and the source of the link.