Docker - docker overview, installation and image operation

Docker overview

1.Docker is an open source application container engine, which is developed based on go language and follows Apache 2.0 0 protocol open source
2.Docker is an open source tool for running applications in Linux container. It is a lightweight "virtual machine"
3.Docker's container technology can easily create a lightweight, portable and self-sufficient container for any application on one host, or use docker to easily create and run containers on multiple hosts

container

definition

The container runs locally on linux and shares the kernel of the host with other containers. It runs an independent process and does not occupy the memory of any other executable files. It is very lightweight

Two important technologies

1. Namespace: docker isolates resources through namespace (namespace, namespace)
2.cgroups: docker restricts resources through cgroups (resource quota)

namespaceSystem call parametersIsolated content
UTSCLONE_NEWUTSHost name and domain name
IPCCLONE_NEWIPCSemaphores, message queues, and shared memory
PIDCLONE_NEWPIDProcess number
NETWORKCLONE_NEWNETNetwork equipment, network stack, port, etc
MOUNTCLONE_NEWNSMount point (file system)
USERCLONE_NEWUSERUsers and user groups

The difference between docker container and virtual machine

characteristicDocker containervirtual machine
Starting speedSecond orderMinute level
Computing power lossAlmost noneThe loss is about 50%
performanceNear primaryweaker than
System support (single machine)Thousands (depending on the business size, generally more than 200)Dozens
operating systemMainly support LinuxAlmost all
IsolationProcess level, resource isolation / restrictionSystem level, complete isolation
Deployment difficultyIt's simpleMulti component, complex deployment
Execution performanceAlmost consistent with the physical systemvm will occupy some resources
Mirror volumeMirror MB LEVELMirror GB level
Management efficiencysimpleComponents are interdependent and complex to manage
network connectionsRelatively weakWith the help of neutron, various network management components can be flexibly implemented

docker core concepts

image

The basis for running the container, which contains all the content required to run the application

container

Running instance created from mirror

Warehouse

Store image images, warehouse categories (public warehouse docker hub, private warehouse harbor)

Install Docker

Environmental preparation

systemctl stop firewalld
setenforce 0

Install dependent packages

yum install -y yum-utils device-mapper-persistent-data lvm2
-------------------------------------------------------
1.yum-utils:Provided yum-config-manager tool
2.device mapper:yes Linux The general device mapping mechanism supporting logical volume management in the kernel provides a highly modular kernel architecture for the implementation of block device driver for storage resource management
3.device mapper Storage driver needs device-mapper-persistent-data and lvm2
-------------------------------------------------------

Set alicloud image source

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Install docker CE and set it to start automatically

yum install -y docker-ce docker-ce-cli containerd.io

systemctl start docker.service
systemctl enable docker.service

Docker image operation

View version information and details

docker version
docker info


Search image (public warehouse)

docker search keyword
docker search nginx

Get and download nginx image

docker pull Warehouse name[:label]
#If no label is specified when downloading the image, the latest version of the image in the warehouse will be downloaded by default, that is, the label selected is the latest label
docker pull nginx

Image accelerated Download

Go to Alibaba cloud image acceleration to find your own accelerator

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://lavnlf3x.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker



View image storage location

6.6 view the image list

#View the download image information list
docker images 

Get image information

docker inspect image id
docker inspect Instances: labels

Add a new label to the image

docker tag Warehouse Name: label new warehouse Name: new label signature

delete mirror

docker rmi Warehouse Name: Label   #When a mirror has multiple labels, only the specified labels are deleted
docker rmi image id  (-f)      #The image will be completely deleted. If the image has been used by the container, the correct way is to delete all containers that depend on the image first, and then delete the image

Save the image and save it as a local file

docker save -o Storage location/Store file name image

Load the image and re import the image file into the image library

docker load < Saved files
docker load -i Saved files

Upload image

Default upload to docker Hub For the official public warehouse, you need to register the account of using the public warehouse https://hub.docker.com 
Click to use docker login Command to enter user name, password and email to complete registration and login.
Before uploading the image, you need to add a new label to the local image before using it docker push Command to upload

docker tag nginx:latest luomo111/nginx:web           #When adding a new tag, you must precede it with the username of your dockerhub 
docker login                                               #Log in to public warehouse
Username:account number
password:password                
docker push luomo111/nginx:web                             #Upload image


Keywords: Linux Docker Container

Added by Crysma on Thu, 10 Mar 2022 13:49:55 +0200