Centos7 install Docker

Centos7 install Docker

View Linux kernel version#####
uname -r

3.10.0- 693.11.1. el7.x86_64
Docker ce supports the 64-bit version Centos7, and requires the kernel version not lower than 3.10
If you have installed Docker ce before, you can remove the previous version and use the following command.
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
Install basic system tools#####
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
If the following error occurs during the installation process, then the Python version of the header of the yum-config-manage file is wrong. It is recommended to check your current Python version and enter Python in the terminal to view it, Python2.7==》Python2, Python3.5 .xx == "Python3 or Python35, it is also possible to change the version of Python, the code does not compile and ask questions, if you change to Python3, you have to replace line 135.
File "/bin/yum-config-manager", line 135
 except yum.Errors.RepoError, e:^
SyntaxError: invalid syntax
Replace code 135 lines
133 try:134     opts = yb.doUtilConfigSetup()135 except yum.Errors.RepoError as e:136     logger.error(str(e))137     sys.exit(50)
There is this kind of error#####
 File "/bin/yum-config-manager", line 159
 print yb.fmtSection('main')^
SyntaxError: invalid syntax
Add () ##### to the print on lines 159,160,196,201,222,233,244,271
159 print(yb.fmtSection('main'))160print(yb.conf.dump())
239,254,261 Try to replace
239: except(IOError, OSError, yum.Errors.YumBaseError)as e:254:  except yum.Errors.DuplicateRepoError as e:261:  except ValueError as e:272:except(IOError, OSError)as e:

Script installation####

You must ensure that the yum package is up to date before installation

yum update

Download and execute the installation docker script

download: curl -fsSl https://get.docker.com -o get-docker.sh
carried out: sudo sh get-docker.sh
After executing the script get-docker.sh, a docker.repo source will be automatically added and Docker will be installed.
Start the docker process
sudo systemctl start docker
Test whether docker is installed successfully
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1 b930d010525: Pull complete 
Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly
If this appears after the test is complete, it means that the docker installation was successful.

The three major components of Docker##

Mirror (image)

Before Docker runs the container, the corresponding image needs to exist locally.

The image is used to create Docker containers. An image can contain a complete operating system environment and other applications required by users. There are a large number of ready-made images available for download in Docker Hub. Docker images are read-only, and one image can create multiple containers.

Container (Container)

Docker uses containers to develop and run applications.

A container is a real column created by an image. It can be started, started, stopped, and deleted. Each container is isolated from each other to ensure a safe platform.

Warehouse (repository)

A warehouse is a place where mirror files are stored centrally.

Each warehouse contains multiple mirrors, and each mirror has a different tag (TAG)

The command to get the image is docker pull
format:    docker pull [Options][Docker Registry address[:The port number]/]Warehouse name[:label]

use: docker pull ubuntu:18.04    

In the above command, the specific mirror warehouse address is not given while pulling the mirror, so the default is to get the mirror from the docker hub, and the mirror name is ubuntu:18.04 mirror, so will get the official mirror library/The label in the ubuntu warehouse is 18.Mirror of 04.

After obtaining the image successfully, run the image next.

Here the ubuntu container is up and running and entered the ubuntu system.

parameter: 
 docker run command to run the container
 - it these are two parameters-i:Interactive operation,-t:terminal
 - - The rm container is deleted immediately after exiting to avoid wasting space. By default, the container will not be deleted automatically and needs to be deleted manually.

List all mirrors

docker image ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              18.04               7698f282e524        2 weeks ago         69.9MB
hello-world         latest              fce289e99eb9        4 months ago        1.84kB

parameter:
 REPOSITORY:warehouse name
 TAG:label
 IMAGE ID:Mirror ID
 CREATED:Creation time
 SIZE:take up space
Mirror volume
docker system df

Phantom mirror

< none><none>              00285df0df87        5 days ago          342 MB

This image originally had the image name and label, which was originally mongo:3.2. With the official image maintenance, after the new version was released, when re-docker pull mongo:3.2, the image name of mongo:3.2 was transferred to the newly downloaded image , And the name on the old mirror was cancelled and became , In addition to docker pull may cause this situation, docker build can also cause this phenomenon, because the new and old images have the same name, the old image name is cancelled, and the warehouse name appears, and the labels are Of the mirror. This type of unlabeled mirroring is also called a hanging mirror. You can use the following command to display this type of mirroring specifically.

docker image ls -f dangling=true

Dangling mirrors are generally useless and can be deleted. Use the following command to delete the hanging mirrors.

docker image prune

List specified mirrors

 docker image ls ubuntu        #ubuntu image name

List a specific mirror

docker image ls ubuntu:18.04    # ubuntu:18.04 Mirror name:18.04 Label

Filter out the image created after ubuntu: 18.04 image

docker image ls -f sinc=ubuntu:18.04

Filter out the images created before ubuntu: 18.04

docker image ls -f before=ubuntu:18.04

The mirrored ID shows the number of mirrors

docker image ls -q

# Mirror ID
7698 f282e524
fce289e99eb9

format template syntax to display the specified field

docker image ls --format "{{.ID}}: {{.Repository}}"

# display
7698 f282e524: ubuntu
fce289e99eb9: hello-world

Display the header row, define the column yourself

 docker image ls --format "table {{.ID}}\t {{.Repository}}\t{{.Tag}}"

# display
IMAGE ID             REPOSITORY         TAG
7698 f282e524         ubuntu             18.04
fce289e99eb9         hello-world        latest

Delete mirror

Before deleting, the mirror must be stopped before it can be deleted.

 docker image rm image ID

Docker runs Nginx

 Get the nginx image
 sudo docker pull nginx

 View the currently running docker image
 docker ps

 Run Nginx image
 sudo docker run -d -p 8000:80--name nginx_test nginx

After running, you can see Welcome to nginx by opening the IP and port in the browser! Then it's successful!

Enter the Docker running container

docker image ls    #View mirror
docker ps          #View running containers
docker ps -a       #View all containers
docker exec -it webserver container name bash

Recommended Posts

CentOS 7 install Docker
CentOS7 install Docker
Centos7 install Docker
Centos7 install docker18
centos7 install docker
CentOS 6 install Docker
Centos8 install Docker
Install Docker on Centos7
CentOS 7 install Docker service
CentOS 8-dnf install docker
install Docker on centos6.5
CentOS 7 install Docker CE
1.5 Install Centos7
Install docker transfer on Centos7
Install docker on Centos system
Centos6 install Python2.7.13
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
Centos7 install Python 3.6.
CentOS7 install MySQL
Centos7 install protobuf
CentOS7 install GlusterFS
ubuntu18.04 install docker
CentOS 7.4 install Zabbix 3.4
Centos6.5 install Tomcat
CentOS install Python 3.6
centos7 install docker-ce 18.01.0
CentOS 7.2 install MariaDB
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
Docker installation (CentOS7 installation)
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
Container study notes CentOS7 install Docker
CentOS6 install mist.io
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Install and use docker under CentOS 6.8
docker install ubuntu
Centos7 install Nginx
CentOS6.5 install CDH5.13
Install Centos7 operating system in Docker
Centos install Python3
CentOS install jdk
centos7 install nginx-rtmp
CentOS8 install MySQL8.0
Centos6.3 install KVM
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS7 docker installation
CentOS 7 install Java 1.8
CentOS8 install fastdfs6.06
CentOS 7 install Gitlab
Centos 7 install PostgreSQL