Introduction to Docker and installation Linux installation Docker Centos installation Docker Ubuntu installation Docker

1. What is Docker?

image
Docker is an open source Container engine built on LXC technology by Docker.Lnc. The source code is hosted on Github, based on the Go language and is open source in compliance with the Apache2.0 protocol.
Docker is a package of Linux containers, providing a simple and easy-to-use container interface.

Docker packages the application and the dependencies of the program in a file. Running this file will generate a virtual container. The program runs in this virtual container as if it were running on a real physical machine. With Docker, there is no need to worry about environmental issues.
Generally speaking, the interface of Docker is quite simple, and users can easily create and use containers, and put their own applications into containers. Containers can also carry out version management, copying, sharing, and modification, just like managing ordinary code.


Second, the concept of Docker

Docker is a platform for developers and system administrators to develop, deploy and run applications using containers. Using Linux containers to deploy applications is called containerization. Use docker to easily deploy applications.

Advantages of containerization:

  • Flexible: Even complex applications can be packaged.
  • Lightweight: The container utilizes and shares the host kernel.
  • Portable: You can build locally, deploy to the cloud and run anywhere.
  • Scalability: You can increase and automatically distribute container copies.
  • Stackable: You can stack services vertically and stack services in a timely and timely manner.

Three, images and containers

Start the container by running images. An images is an executable package that includes all the content needed to run the application-code, runtime, libraries, environment variables, and configuration files.


Container-time images runtime example-when executed (ie, images state, or user process) in memory, you can use the command docker ps to view the list of running containers, just like in Linux.


Fourth, install Docker

Install Docker on Ubuntu

One, install docker method one

apt install docker.io

Two, install docker method two

  • Uninstall the old version of docker
  • For a new installation, this step is not necessary
apt-get remove docker docker-engine docker.io
  • 1. Update the apt package index
apt-get update
  • 2. Install the following packages so that apt can use the repository via HTTPS
apt-get -y install apt-transport-https ca-certificates curl software-properties-common

  • 3. Add Docker's official GPG key
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

  • 3.1 add warehouse
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  • 4. Update the apt package index again
apt-get update
  • 5. Install the latest version of Docker CE
apt-get -y install docker-ce
  • 6. View the installed Docker
docker version

Centos install Docker

  • First remove unofficial Docker packages
yum -y remove docker docker-common container-selinux
  • Install yum-utils toolkit
yum install -y yum-utils
  • Configure the official installation source of Alibaba Cloud Docker
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  • After the configuration is complete, update the system yum installation source
yum update -y
  • Install the latest version of docker-ce
yum -y install docker-ce
  • Check the docker version after installation
docker version

Client: Docker Engine - Community
 Version:           19.03.11
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        42e35e61f3
 Built:             Mon Jun  1 09:13:48 2020
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
  • 如果提示你 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

solution

systemctl enable docker # 添加开机启动
systemctl daemon-reload # xxx
systemctl restart docker.service # 重启Docker服务
# 再次输入 docker version
docker version

Client: Docker Engine - Community
 Version:           19.03.11
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        42e35e61f3
 Built:             Mon Jun  1 09:13:48 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.11
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       42e35e61f3
  Built:            Mon Jun  1 09:12:26 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

# 成功!

Configure Docker image accelerator

  • Exclusive image accelerator from Alibaba Cloud's container image acceleration service
  • Get an exclusive id for free, see the bottom for details
https://4670ldli.mirror.aliyuncs.com 
  • 7. Modify the daemon configuration file /etc/docker/daemon.json to use the accelerator for the first modification without this file, then use the following command to create and write
先输入 tee /etc/docker/daemon.json <<-'EOF'  回车

从这

{
  "registry-mirrors": ["https://4670ldli.mirror.aliyuncs.com"]
}

EOF
复制到这里
  • 8. Restart docker
systemctl restart docker
  • 9. Enter the following to view the accelerated mirror source
docker info
  • 10. The process of installing tomcat is slow. Do not stop halfway while watching the internet speed.
docker pull tomcat
  • 11.Check the docker warehouse to see if there is tomcat
docker images
  • 11. Run hello-world
docker run hello-world

The output Hello from Docker! means that the installation is successful!

img

  • 12. Run tomcat
docker run -p 8080:8080 --name -d tomcat  #好像用不了
docker run -d --name tomcat -p 8081:8080 tomcat

Host port 8080: Container port 8080
without -d means tomcat is running in the
foreground, otherwise it is running in the background. Tomcat running in the foreground will be blocked on the screen

-d is running in a daemon state, which means it will not block on the screen but run in the background

Attached. Docker enables remote access permissions

  • Modify the configuration file and open port

    2375. If you are not sure of the docker.service file path, enter
    dpkg -L package name
    dpkg -L docker-ce
vim /lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// 

Replace this sentence
↑ ↑ ↑
with
↓ ↓ ↓ --- containerd
remains unchanged

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375

Reload the configuration file and start:

#重新加载配置
systemctl daemon-reload
#重启docker
systemctl restart docker

vi editor paste

先按 Esc 冒号: 输入 set paste 回车再进行粘贴
否则yml格式会错乱

Get Alibaba Cloud Image Accelerator

Alibaba Cloud Image Accelerator URL
image

  • After obtaining the address, follow the above tutorial to install

End to spread flowers

Author: yufire © [email protected]

Guess you like

Origin blog.csdn.net/weixin_43420255/article/details/106495068