Common commands for Docker images
1. Search image
Docker Search Java
The table contains five columns:
-name: Mirror Warehouse Name
-description: Mirrored Warehouse Description
-stars: The number of mirrored warehouse collections, indicating the popularity of the mirrored warehouse, similar to the STARS of GitHub
-offical: Indicates whether it is an official warehouse, and the image labeled "OK" in this column is created and maintained by the official project group of each software.
-automated: Indicates whether it is a mirrored warehouse that is built automatically
2. Download the image
Use the command Docker Pull:docker pull Java to download the latest Java image from the Docker hub
Docker pull Reg.itmuch.com/java:7 Specify the image label you want to download and the Docker registry address, download the Java image labeled 7 from the Address
3. List the Mirrors
Docker images lists images that have already been downloaded
The table contains 5 columns:
-repository: The name of the warehouse to which the image belongs
-tag: Mirror label. The default is latest, which indicates the latest
-image ID: Mirror ID, which represents the unique identity of the mirror
-created: Mirror creation time
-size: Mirror Size
4. Deleting a local mirror
Use the Docker RMI command to delete a specified image
Exm:docker RMI Hello-world
Remove all mirrors
Exm:docker Rmi-f $ (Docker images)
-F means forced removal
Common commands for Docker containers:
1. Create and start a container: Use Docker run to create and start a container
The command contains many options:
-D: Indicates background run
-P: Random port mapping
-P: Specify port Mappings in the following four formats
-Ip:hostPort:containerPort
-Ip::containerport
-Hostport:containerport
-Containerport
--network: Specifies the network mode, which has the following optional parameters:
---network=bridge: The default option, which means connecting to the default bridge.
---network=host: The container uses the host's network
---network=container:name_or_id: Tell Docker to let the new container use the network configuration of the existing container
---network=none: The network configuration of the container is not configured and the user can customize the network
Exm:a.docker run Java/bin/echo ' Hello world '
B.docker run-d-P 91:80 nginx background boot an nginx container. -D background Run,-P open container port to host port
Note: When Docker run creates a container, it checks for local presence, does not exist, and automatically downloads the image from the Docker hub and launches a Docker container
2. List containers
Docker PS
If you need to list all containers (containing stopped containers), you can use the-a parameter
The table contains 7 columns:
-CONTAINER_ID: Represents the Container ID
-image: Indicates the name of the mirror
-command: Represents the command that is run when the container starts
-created: Indicates when the container was created
-status: Represents the state in which the container is running. Up means running, exited means stopped
-ports: Indicates the port to which the container is external
-names: Represents the container name. The name is automatically generated by Docker by default, or you can use the--name option of the Docker Run command to specify it yourself
3. Stop the container
Use Docker stop container ID/container name
4. Force Stop Container
You can use the Docker kill command to send a sigkill signal to force a stop container: Docker kill container ID
5. Start a stopped container
Docker start container ID
6. Restart the container
Docker restart
7. Enter the container
In a scenario, you may need to enter a running container
-Use the Docker attach command to enter
Docker attach 784fd3b294d7. In many scenarios, using the Docker attach command is not convenient, and when multiple windows are attach to the same container at the same time, all the Windows will be displayed synchronously. Similarly, if a window is blocked, other Windows cannot
Perform actions
-Use Nsenter to enter the container
The Nsenter tool is included in the Util-linux 2.23 or later version. In order to connect to the container, you need to find the PID of the first process in the container, which can be obtained using the following command:
Docker Inspect--format "{{. State.pid}} "$CONTAINER _id
Once the PID is obtained, you can use the Nsenter command to enter the container:
Nsenter--target "$PID"--mount--uts--ipc--net--pid
8. Delete a container
To delete a specified container using the Docker RM Container ID command
This command can only delete containers that have stopped, and if you want to delete a running container, use the-f parameter
Delete all containers:
Docker Rm-f $ (Docker ps-a-Q)
Reference:
1.http://itmuch.com/docker/docker-2/