Docker basic commands
Basic knowledge of
Iso file container: VM Dockerfile: c program source file xxx.c container Data volume: shared folder
Basic commands
View local images: Docker images [options]
-a: lists all mirrors in the repository. -q: displays only the iD numbers of all ests. — Digests: displays summary information
Example: –digest –no-trunc: Displays complete information
Docker search [options] xx image name
-filter=stars=30: indicates that the number of likes is greater than 30. –no-trunc: indicates that the information is not omitted. — Automated: lists only the images of the automated build type
Docker pull xx image :[version number] (can also write the image ID)
No version number added at the end: XXX is the latest version by default
Delete a local image :docker rmI [option] xx Image name (or ID): latest version by default
-f Mirror 1: version 2: version: Forcibly deleted
Example: -f ${docker images -qa} delete all
Container command (image before container)
Docker run [option] [command] [args]
[command] [args] : indicates the command to be executed by the container and the parameters of the command are: /bin/bash [option]: indicates parameters
-d: indicates that the container id is returned but the container is not entered. -I: indicates that the container is run in interactive mode. The container is usually used together with -t. Port mapping can be specified in the following forms
- Hostip: hostPort: containerPort
- Hostip: : containerPort
- HostPort: containerPort
- containerPort
Example: docker run –name myKali -p 127.0.0.1:8888:8080 kali:19.4 /bin/bash
View all running containers :docker ps [options] shows running containers by default
-a: running and historically running -l: displays the latest created containers. -n 3: displays the last three created containers. -q: in silent mode, only the container number is displayed
Exit container (inside container):
CTRL + P + Q: Exit the container without closing it
Start container (previously closed):docker start -i container ID
Run the following command to restart the container :docker restart -i Container ID
Stop container :docker stop container ID
Forced stop container :docker kill container ID
Delete a stopped container :docker RM container ID
Docker logs -f -t –tail num Container ID
View the processes running in the container :docker top Container ID
Docker inspect Container ID
Enter the running container and interact with the command line:
Docker attach container ID: directly enter the container docker exec-it container ID ls -l /temp: execute the command inside the container outside, obtain the result, can enter the container, or not
Docker cp Container ID: Inside path Path of the destination host
Docker commit -m= description -a= author container ID Name of target image to create :[version number]
Docker push [OPTIONS] NAME[:TAG]
–disable-content-trust Ignores the verification of mirrors. This function is enabled by default
Container data volume:
Method one:
Docker run -v/Host absolute path Directory :/ Container directory: permission Image name Permission The default value is read and write
Method 2:
- Create a XXX folder under the host
- Write another one in this directory
.ockfile
File Dockerfile docker built -f /xxx/Dockerfile -t xx/xxx
The image name is xx/ XXXdocker run -it xx/xxx
Data volume container:
Docker run-it –name docker run-it –name docker02 –volumes from docker01 And share data volume files