Docker installation steps and commands

Official website: https://www.docker.com/

Demo system: Centos 7

  firewalld   On, selinux   open

I. install the repository expansion package

yum install yum-utils -y

II. Setting the repository

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

III. installation of three packages

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

##  docker-ce   Package,   Docker CE cli, toolkit, containerd.io   It is mainly used for system and Docker api daemons  

IV. start docker

systemctl start docker

V. verification

1. View docker version information:

docker version

2. Query docker details:

docker info

Vi. view local image

docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Warehouse name label ID of the image (guaranteed to be unique) Creation time size

VII. Find image

docker search nginx
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                             Official build of Nginx.                        15732     [OK]       
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con...   2088                 [OK]
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of...   818                  [OK]

##OFFICIAL here   ok indicates that it is an OFFICIAL image  

VIII. Download Image

docker pull nginx

IX. create containers directly using images

            1. The foreground starts the container, the window closes, and the process closes automatically

docker run + parameter [images:tag] start command

docker run --name nginx_1 nginx:latest

##Nginx: latest, which is the label

2. Start nginx in the background

docker run -d --name nginx_2 nginx

##  nginx_ two   This means that the name of the container is nginx_2. The last nginx here represents the image used

3. In interactive mode, and assign a pseudo terminal to run the container

docker run -itd --name nginx_5 nginx
- i run the container in interactive mode
- t reassign a pseudo terminal to the container
##- d if the startup is unsuccessful, you can start it with - itd (generally, the official direct can use - d)
X. create containers and expose ports
docker run -itd -p 9527:80 --name nginx_4 nginx:latest

##  9527   It is the port exposed to external access. You can access the services in the container by accessing port 9527 of the host

##Host 9527   And 80   An intranet will be generated between, but access to port 80 of the intranet through 9527

##Access container:   Browser input native IP:9527  

Xi. Viewing containers

1. You can only view the container that has been started
docker ps

2. View all containers (including those not started)

docker ps -a

  3. Directly view the container ID

docker ps -aq

Xi. Enter the container and assign a pseudo terminal interactively

docker exec -t 80db5c362fb3 /bin/bash

##  80db5c362fb3   This ID is via docker   ps   Get, / bin/bash interpreter   Cannot enter container without interpreter

XII. Start and stop the container

docker start/stop [container ID]

XIII. Delete container

docker rm 83023b4bead2

##Started containers cannot be deleted. You must stop starting to delete them

XIV. Delete all stopped containers

docker rm `docker ps -aq`
##You will be prompted to delete the stopped container, and an error will be reported when deleting the running container
XV. View image or container details
docker inspect 83023b4bead2

XVI. Add a soft connection to the image and rename and label it:

docker tag nginx:latest centos_nginx:1

##The image id is the same

XVII. Delete image

docker rmi nginx:latest

##If it is not necessary, it is better not to delete the mirror.

XVIII. File replication between container and host

1. Host to container:

docker cp test,txt 80db5c362fb3:/root

##Copy test.txt in the current directory   To 80db5c362fb3 the root under this image

  2. Container to host machine:

docker cp 80db5c362fb3:/root/f1 . 

19. Do not enter the container to view | create | delete | files in the container

docker exec 80db5c362fb3 ls /root

##Add / bin/bash   Enter the container, add the command directly, and execute the command without entering the container

 

 

Tags: Docker

Posted on Tue, 02 Nov 2021 01:48:55 -0400 by bleh