Learning Docker, you first need to understand the basic concepts of Docker, we introduced the basic principles of docker in the previous article and deploy the operating system.
Speaking today at embedded development docker client commonly used commands, entered a "hands-on" phase (that is, knock Docker command). Docker command more, here we summarize Docker commonly used commands for easy access to small partners.
The client list of common commands
The following is a list of commonly used commands Docker client, you can use these commands to browse through the docker COMMAND --help.
attach: a container attached to the running;
build: from a Dockerfile create a mirror;
commit: Create a new image from a modified container;
cp: Copy between the container and the local host file system;
create: Create a new container, but does not run it;
diff: Check within a container file system modifications, including modifications and additions;
events: Get real-time events from the server;
exec: Run operation within the container;
export: deriving a tar content of the container package;
history: shows the history of a mirror;
images: image lists exist;
import: import a file (typically a tar package) path or directory to create a local image;
info: Displays some relevant system information;
inspect: Displays a specific container configuration information;
kill: shut down a running container (including all related processes and resources);
load: Load one image from a tar package;
login: Register or log in to a server Docker's warehouse;
logout: logout from Docker warehouse server;
logs: acquiring the log information of the container;
network: the network management Docker, including view, create, delete, mount, unloading;
node: Management swarm nodes in the cluster, including the view, update, delete, upgrade / cancel the management node and so on;
pause: suspend all processes in a container;
port: Find a nat to a private network port public port;
ps: List container host;
pull: the repository server from a Docker pull-down image or a warehouse;
push: a mirror or a repository push Docker registration server;
rename: Rename a container;
restart: restarting a container running;
rm: remove the given number of containers;
rmi: remove the given number of mirrors;
run: create a new container, and runs a given command;
save: save image as a tar package file;
search: search Docker index in a mirror;
service: Docker management initiated by application services, including create, update, delete, and so on;
start: start a container;
stats: output (s) of the container resource usage statistics;
stop: terminating operation of a container;
swarm: Docker swarm cluster management, including create, join, quit and updating;
tag: a tag hit mirror;
top: View process information in a container running;
unpause: all processes within a container recovery from the suspended state;
update: Update of several containers in the specified configuration information;
version: output version information Docker's;
volume: management Docker volume, including view, create, delete, and so on;
wait: blocking a vessel until termination, and outputs its exit character.
Docker two graphs summarize command
Container event state diagram
Docker command profile
Common actions and commands
Common mirroring operation
Listed Mirror
docker images
Remove Mirror
docker rmi [-f] <IMAGE ID>或docker image rm [-f] <IMAGE ID>
Wherein -f force delete representatives, with a corresponding one of a plurality of containers in a mirror
A mirror to play tag
docker tag
Common container operations
Listed on the main container
docker container ls [-a]
Taking a mirror-based container up and running
docker run -itd --privileged=true --cap-add=SYS_ADMIN --mount type=bind,src=/data/home,target=/root/workspace -p 30000:22 <IMAGE ID> bin/bash
Parameter Description:
-i interactive representation, so that the vessel remains open standard input
-t represents the docker so assigned and bound to a pseudo-terminal input standard container
-d represents the vessel will enter start running in the background
--privileged = true representation allows the vessel to run some privileged commands
--cap-add = SYS_ADMIN representation available to a larger container management authority
-v is binding mount directory
-p port mapping relationship indicates that the specified internal host ports and container
bin / bash expressed as docker must run a background process, otherwise it will exit the vessel.
Heavy naming container
docker rename old_name new_name into the background of the container (after entering this way, does not cause the vessel to stop, there is a command into the background of the container can also attach the implementation of exit, but the exit will cause the container to stop)
docker exec -it container_name bin/bash
Termination container
docker container stop
Restart the termination of the state of the container
docker container start
Terminating a container and then restart operating mode
docker container restart
Delete termination state container
docker container rm container_name
Remove the runtime state of the container
docker container rm -f container_name
Clean up all termination state container
docker container prune
View information containers
docker inspect container_name
View container corresponding host port:
#docker port container_name或#docker port container_name <PORT_NUMBER>
Based on a new base image New Container
1. Find the official repository mirror
docker search ubuntu
We can see a lot of return image contains keywords, including image name, description, collection number (indicating the degree of concern of the mirror), whether official create, whether created automatically
2. Download the image to your local
docker pull ubuntu:18.04
3. View the downloaded image
docker images
4. run and load the image into a container
docker run -itd --privileged=true --cap-add=SYS_ADMIN --mount type=bind,src=/data/home,target=/root/workspace -p 30000:22 <IMAGE ID> bin/bash
5. Push mirrored to a remote repository
docker push
Save and open container
Container export file and then import the file as a local mirror, it will lose the history and metadata can not roll back to the previous layer, exported slightly smaller package.
1. First, get container id
docker container ls
2. Export the contents of the container into a tar package
docker export <CONTAINER ID> > /home/export.tar
3. Import a file (typically a tar package) to create a local mirror path or directory, you can reassign the mirror name.
cat xxx.tar | docker import - new_name:new_tag
or:
Import snapshot of the container from the specified URL or a directory:
docker import http://example.com/exampleimage.tgz example/imagerepo
4. load the image into a container, the container and start
docker run
Save the image and open
Mirroring the export file and then import the file as a local mirror, do not lose the history and layer, layer rollback
1. View Mirror id
docker images
2. Export mirroring the contents of a tar package
docker s ave <IMAGE NAME> > /h ome/save.tar
3. Load a mirror from a tar package, the name can not be reassigned mirror
docker load < /home/save.tar
4. Check the imported image id
docker images
The above command covering the basic commonly used in embedded development docker command, would like to know more you can see:
Docker official home page: https: //www.docker.com
Docker official blog: https: //blog.docker.com
Docker official document: https: //docs.docker.com
I hope you see it something that points out issues of common progress, gain more knowledge in technical support and share in Feiling.