Docker is not introduced. It can be used quickly. The docker instruction is used

Problem background

The previous article introduced the quick installation and deployment of docker. This chapter introduces the use of quick docker instructions
matters needing attention:

  • Centos7 is installed by default
  • JDK is installed by default
  • root permission is enabled by default

Docker instruction usage

1 view image
docker images

View all mirror ID S

docker images -q

2 search image
docker search [imageName Image name]
3 pull the image. If the version number is not specified, it is the latest version, Check the official website docerHub to check the version number
docker pull [imageName Image name]:[version Version number]
4. Delete the image, and rmi is remove image
docker rmi [imageId image ID]

Batch delete image

docker rmi `docker images -q`
5 view the running docker container
docker ps
6 view all containers, including those that are running and those that have stopped
docker ps -a
docker ps -all
7 last running container
docker ps -l
8 view containers that have been stopped
docker ps -f status=exited
9 create container directive

docker run parameter image name: image label / bin/bash

## Detailed explanation of command parameters
-i: Represents the running container,If this parameter is not added, the container will be created through image instead of startup.

-t: Indicates that the container will enter its command line after it is started. After adding these two parameters, the container creation can log in. That is, assign a pseudo terminal(If
 Only add it Two parameters, which will automatically enter the container after creation). 

-d: stay run Add after-d parameter,A daemon container will be created to run in the background (so that the container will not be logged in automatically after the container is created).
--name :Name the container you created. Background start

-v: Represents the directory mapping relationship (the former is the host directory, and the latter is the directory mapped to the host). Multiple directories can be used-v Make multiple directories
 Or file mapping. Note: it's best to do directory mapping, modify it on the host, and then share it on the container.

-p: Indicates port mapping. The former is the host port and the latter is the mapped port in the container. Multiple can be used-p Do multiple port mapping, for example:
Can Docker in Tomcat If the 8080 port of the container is mapped to a port 8080 on the host, it can be accessed later tomcat Just
 To: http://Host IP: 8080/
After entering the container, initialize the executed command:/bin/bash;Can write but not write
10 interactive container, that is, after running the container, it will automatically log in and enter the container
docker run -it --name=[Container name] [Image name]:[Label version number] /bin/bash

Exit container

exit
11 guarded container, running in the background
docker run -di --name=[Container name] [Image name(Or mirror ID)]:[Label version number] /bin/bash
12 log in to the container / enter the directory of the container. The script / bin/bash executed after logging in to the container here must be written, and the above can not be written
docker run -di --name=[Container name] [Image name(Or mirror ID)]:[Label version number] /bin/bash
13 stop container
docker stop [Container name (or container) ID)]
14 start up container
docker start [Container name (or container) ID)]
15. Copy host files to container
docker cp [Files or directories to be copied] [Container name]:[Container directory]

For example, copy to the webapps directory of the tomcat container

docker cp lagou.html 59b35c0bbe6d:/usr/local/tomcat/webapps

Switch to tomcat container to view, / bin/bash is required

docker exec -it [tomcat container ID] /bin/bash
16 copy container files to host
docker cp [Container name or ID]:[Container directory] [Files or directories to be copied]

For example, copy to the file in the tomcat container and then copy it out

docker cp 59b35c0bbe6d:/usr/local/tomcat/webapps/lagou.html ./
17 directory mount, create a container, add the - v parameter, and then the host Directory: container directory
docker run -di -v /usr/local/myhtml:/usr/local/myhtml --name=mycentos3 centos:7
18. Check various data of the container, including IP, directory, MAC address, port, gateway, etc
docker inspect [Container name (container) ID)]

Direct output IP

docker inspect --format='{{.NetworkSettings.IPAddress}}' [Container name (container) ID)]
19 delete the container. The running container cannot be deleted
docker rm [Container name (container) ID)]
20 delete image
docker rmi [image ID(Image name)]

summary

  • Students who are familiar with docker can directly use the instructions in this article to quickly pull the required containers




As a programmer, the 51st article, write a lyric every time, record it, and see how many songs there are in life, wahahaha

Lyric: take advantage of the time

Keywords: Operation & Maintenance Docker Container

Added by Fahid on Sat, 05 Feb 2022 09:45:58 +0200