“This is the fourth day of my participation in the August More Text Challenge. For details, see: August More Text Challenge.”
1. Start/stop the container
Create and start a container for an SRS image
$ docker run -it --restart=always -p 1985:1985 -v /dev:/dev2 -v /mnt/nfs:/mnt/volume1 --name srs-service srs
Copy the code
- –restart=always indicates that startup is enabled
- -p 1985:1985 indicates the mapping between the host port and the Docker port
- -v/MNT/NFS :/ MNT /volume1 indicates that the local/MNT/NFS directory is mounted to the container/MNT /volume1 directory
- SRS indicates the mirror identifier
Start/stop the container
# start
$ docker container start xxx
# end
$ docker container stop xxx
# Query modify
$ docker container diff xxx
Copy the code
2. Enter the container
Container list (the -a command is used to view all created containers with terminated status)
$ docker container ls -a
Copy the code
Into the container
$ docker exec -it xxx /bin/bash
Copy the code
- XXX is the container identifier
- You can update a container using docker Container Update, e.g. docker Container Update –restart=”no” < container ID >
3. Export and import containers
Export container
To export a snapshot of a local container, use the docker export command
$ docker export xxx > container20201216.tar
Copy the code
Import the container
Use Docker import to import images from container snapshot files, for example
$cat container20201216. Tar | docker import - SRS/SRS: v1.0Copy the code
Alternatively, you can import by specifying a URL or a directory, for example
$ docker import http://example.com/exampleimage.tgz example/imagerepo
Copy the code
4. Delete the container
You can use Docker Container RM to remove a container that is in the terminated state, such as
$ docker container rm trusting_newton
Copy the code
If there are too many containers to delete one by one, use the following command to clear all the containers in the terminated state.
$ docker container prune
Copy the code
5. Information about the container
PID information
$ docker inspect --format '{{ .State.Pid }}' <CONTAINER ID or NAME>
Copy the code
The IP address
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID or NAME>
Copy the code
The container configuration
$ docker inspect <CONTAINER ID or NAME>
Copy the code
Container monitoring
$ docker stats
Copy the code
Containers that are already running, Can through the docker update to update configuration parameters < CONTAINER ID or NAME > (the operation of the need to stop the CONTAINER) or by the/var/lib/docker/containers/hostconfig under the CONTAINER ID. Json And modify startup configuration parameters
6. Control the usage of container system resources
When a container is created using the Docker create command or created and started using the Docker run command
- You can use
-c|--cpu-shares[=0]
Parameter to adjust the weight of the CPU used by the container - You can use
-m|--memory[=MEMORY]
Parameter to adjust the size of memory used by the container.