编程知识 cdmana.com

Installation and basic operation of docker (application container engine)

writing | Brother Ping date | 20201112

One 、Docker brief introduction

Docker Is based on Go Language Implementation of open source container project . It is expected to achieve the project operation environment “ One time encapsulation , Run anywhere ” Purpose .

Study Docker The main purpose is to be able to do two things :
1. stay Docker Install the software
2. Deploy the project to Docker

Docker framework :

Docker It's installed on the host computer Daemon Background program to receive client commands , Create a container instance , Pull or create an image from the remote mirror repository center .

Two 、Docker Installation and startup

Docker Yes windows and linux edition . This operation is to install in Linux It was demonstrated on the .
The following installation steps are based on CentOS8, You need to make sure that the virtual machine can connect to the Internet .

1.Docker install

Step 1 Upload installation package

Docker Installation can be divided into online installation and local installation , Due to the need to connect Docker Official website , Internet speed is moving and easy to fail , So I used a local installation .
Specific installation package :
link : https://pan.baidu.com/s/1QYwL... password : ljsk

Upload the downloaded installation package to CentOS in :

Step 2 Install dependencies and Docker

Use yum localinstall Command to install separately :
1、 Install first containerd.io:

# yum localinstall containerd.io-1.2.6-3.3.fc30.x86_64.rpm 

2、 install docker-ce:

# yum localinstall -y libcgroup
# yum localinstall -y docker-ce-cli-19.03.12-3.el7.x86_64.rpm
# yum localinstall -y docker-ce-19.03.12-3.el7.x86_64.rpm

Step 3 Start and check Docker

Start command :

# systemctl start docker

see docker Information :

# docker info

The result is shown in Fig. :

Step 4 Alicloud image accelerator configuration

By default Docker from Docker Hub Download the image resources , But it's slow , It can be solved by configuring the domestic mirror accelerator .
Log in to Alibaba cloud console , Input “ Container image service ” To search , Click on “ Image accelerator ”:

After installation Docker On , Follow the page instructions to configure daemon.json Configuration file and restart to complete the configuration .

3、 ... and 、Docker Mirror operation

3.1 List all local images

command :

# docker images

The result is shown in Fig. :

Interpretation of the results :
REPOSITORY: Warehouse name of the image
TAG: Image label ( It's the version )
IMAGE ID: Mirror image ID
CREATED: Image creation date ( It's not the date of getting the image )
SIZE: Image size

3.2 Search for remote mirrors

If there is no mirror image needed locally , You can go to the remote mirror warehouse center to search , command :

# docker search mysql

The result is shown in Fig. :

Interpretation of the results :
NAME: Warehouse name
DESCRIPTION: Image description
STARS: User evaluation , Reflect the popularity of a mirror image
OFFICIAL: Is it official
AUTOMATED: An automated build , Indicates that the image is created by Docker Hub Automatically build process created

3.3 Pull the mirror image

Use the following command , You can pull the image from the remote image warehouse :

docker pull mysql:latest

Four 、Docker Container operation

Can be Docker The container is seen as the simplest Linux Environmental Science ( Including the system kernel 、root User permissions 、 Process space 、 Cyberspace and user space ) And the applications running in it ( such as MySQL).

4.1 The new container

command :

docker create [options]  Image name or ID

for example :

# docker create --name mysqlgcp -p 3307:3306 -e MYSQL_ROOT_PASSWORD=root mysql:latest

Parameter description :
--name: Used to rename the created container
-p: Host and docker Port mapping for container ,hostPort:containerPort
-e: Set parameters
It's possible to use -v: Directory mapping relationship between host and container ,":" Before the host Directory , Then the container Directory

The container above creates , But it's not running .

4.2 Look at the container

The following command looks at the local running container :

# docker container ls

If you want to see all the containers that have been created , This includes containers that are not running ( Such as 4.1 Created container ), Join in -l Parameters :

# docker container ls -l

result :

Description of other commonly used parameters :
-n Numbers : According to recent n Containers created
-a: List all running containers
-q: List containers id

4.3 Start the container

Use the following command to start the created container :

# docker start mysqlgcp
 or :
# docker start 52bdd1defcd8

You can use the container name or container ID

4.4 Interact with running containers

Use the following command to interact with the running container :

# docker exec [option]  Containers ID [command]

for example :

docker exec -it 52bdd1defcd8 /bin/bash

Parameter description :
-i: Run container in interactive mode , Usually with -t Continuous use
-t: Reassign a pseudo terminal to the container , Usually with -i Continuous use

The effect is as shown in the picture :

Exit from the container terminal , Use exit command

4.5 Stop container

The order is as follows :

# docker stop  Container name or container ID

4.6 Create and run the container

The order is as follows :

# docker run [options]  Image name or mirror image ID [COMMAND] [ARG...]

Examples of specific orders are as follows :

# docker run -p 3307:3306 --name mysqlgcp -e MYSQL_ROOT_PASSWORD=root -d mysql:latest

版权声明
本文为[Pingge]所创,转载请带上原文链接,感谢

Scroll to Top