Docker Command Tutorial
Docker since the birth has been very popular, learning Docker is a very cool, very interesting things. I hope that through this article can let you quickly get started Docker, and have some learning results to stimulate their interest in learning. I am also just a child playing in Docker this whale, the full text if there is ambiguous, incorrect place, also please treatise.
# docker--help Usage:docker [OPTIONS] COMMAND [arg ...]
Docker daemon [--help | ...]
Docker [-H |--help |-v |--version] A self-sufficient runtime for containers. Options:--config=~/.docker Location of client config files-d,--debug=false Enable debug Mode-h,--hos T=[] Daemon socket (s) to connect to-h,--help=false Print usage-l,--log-level=info Set the Loggi NG level--tls=false use TLS; Implied by--tlsverify--tlscacert=~/.docker/ca.pem Trust Certs signed only by this CA--TLSCERT=~/.DOCKER/CERT.PEM Pa Th to TLS certificate file--tlskey=~/.docker/key.pem Path to TLS key file--tlsverify=false use TLS and verify The Remote-v,--version=false Print version information and quit Commands:attach attach to a running contain Er--attaches the terminal to the container 1> runs an interactive container [root@localhost ~]# Docker run-i-t Centos/bin/bash [roo t@f0a02b473067/]# 2> View the container on another window.Status [root@localhost ~]# docker ps-a CONTAINER ID IMAGE COMMAND CREATED status PO
RTS NAMES d4a75f165ce6 CentOS "/bin/bash" 5 seconds ago up 5 seconds Cranky_mahavira 3> exit the container running in the first step [Root@d4a75f165ce6/]# exit Exit 4> View the state of the container [root@localhost ~]# Docker ps-a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4a75f16 5ce6 CentOS "/bin/bash" 2 minutes ago exited (0) seconds ago Cranky_mahavira is visible at this time the state of the container is exited, So, how do you run this container again?
You can use the Docker Start command 5> run the container again [root@localhost ~]# Docker start Cranky_mahavira Cranky_mahavira 6> view the state of the container again [root@localhost ~]# Docker ps-a CONTAINER ID IMAGE COMMAND CREATE D STATUS PORTS NAMES d4a75f165ce6 CentOS "/bin/bash" 6 minutes ago up seconds CrankY_mahavira because the container is interactive, but at the moment we find that there is no specific terminal to interact with, you can use the Attach command. 7> through the Attach command [root@localhost ~]# docker Attach Cranky_mahavira [Root@d4a75f165ce6/]# Build
Build the image from a dockerfile--create a mirrored commit created by dockerfile a new image from a container ' s changes
--Create a local mirror from a container note: If you are going to push into the Docker hub, note that the name of the generated mirror [root@localhost ~]# Docker commit CENTOS_V1 CENTOS:V1
68ad49c999496cff25fdda58f0521530a143d3884e61bce7ada09bdc22337638 [root@localhost ~]# Docker push CENTOS:V1 You cannot push a "root" repository. Please use CENTOS:V1 rename your repository to <user>/<repo> (ex: <user>/centos) because it is pushed to Docker When the hub is pushed to the appropriate user, the user name must be specified. For example, my username is ivictor, then the newly generated local mirror name is: Docker push Victor/centos:v1, where V1 is tag, can not write, the default is latest CP Copy Files/fold ERs from a container to a hostdir or to STDOUT-copy file between host and container the use of CP is as follows: Usage:docker CP [OPTION S] CONtainer:path localpath|-Docker CP [OPTIONS] localpath|-Container:path need to be aware of-usage, I created two text files in the container, one of which is T Est.txt, the contents are as follows: root@839866a338db:/# cat Test.txt 456 Another file is Test1,txt, content is: root@839866a338db:/# The results of cat test1.txt HelloWorld usage One are as follows: [Root@localhost ~]# Docker CP Mysqldb:/test.tar-test.tar 0100644000000000000000000002400012573523153010736
0ustar0000000000000000test.txt000064400000000000000000000000141257352311101 1267 0ustar rootroot123 789 The results of test1.txt0000644000000000000000000000001312573523124011353 0ustar Rootroothelloworld Usage II are as follows: [root@local
Host ~]# cat Test.tar |docker cp-mysqldb:/ [Root@localhost ~]# docker exec-it mysqldb/bin/bash root@839866a338db:/# ls bin Dev entrypoint.sh h ome lib64 mnt proc run selinux sys test.txt tmp var boot docker-entrypoint-initdb.d etc Lib Media opt Roo T sbin srv test.tar test1.txt usr--There are two new files in the container, Test.txt and Test1.txt, and this is the Test.tar file created create a new container--Create a fresh container, note that at this point, the status of the container is only CRE ated diff Inspect Changes on a container ' s filesystem--View the changed files in the container, take my MySQL container as an example [Root@localhost ~]# Docker diff mysqldb C/root a/root/.bash_history a/test1.txt A/test.tar a/test . txt C/run c/run/mysqld a/run/mysqld/mysqld.pid A/run/mysqld/mysqld.sock is not difficult to see,
C corresponds to the directory, a corresponds to the file events get real time event from the server--the real-time output of Docker servers, including container creation, startup, shutdown, and so on. For example: [root@localhost ~]# Docker Events 2015-09-08t17:40:13.000000000+08:00 d2a2ef5ddb90b505acaf6b59ab43eecf7e ddbd3e71f36572436c34dc0763db79: (from WordPress) Create 2015-09-08t17:40:14.000000000+08:00 d2a2ef5ddb90b505acaf6b5 9ab43eecf7eddbd3e71f36572436c34dc0763db79: (from WordPress) Die 2015-09-08t17:42:10.000000000+08:00 839866A338DB6DD 626fa8eabeef53a839e4d2e2eb16ebD89679aa722c4caa5f7: (from MySQL) start exec Run a command in a running container--after the container is started, perform other tasks through The EXEC command can create two types of tasks: background and interactive task background tasks: Docker exec-d cc Touch 123 where CC is a container name Interactive task: [Root@localhost ~]# Dock Er exec-i-t cc/bin/bash root@1e5bb46d801b:/# ls bin boot dev etc home lib lib64 media mnt opt proc Root Run SBI
n SRV sys tmp usr VAR export export a container ' s filesystem as a tar archive--there are two ways to package a container's file system into a tar file: Docker Export-o Mysqldb1.tar mysqldb Docker export mysqldb > Mysqldb.tar History Show the History of An image-Displays the process of mirroring production, equivalent to dockfile images list images-Lists all mirrors of this machine import import the contents from a Tarball to create a filesystem image-creates a new mirror based on the contents of the tar file, corresponding to the previous Export command [root@localhost ~]# docker import m Ysqldb.tar mysql:v1 eb81de183cd94fd6f0231de4ff29969db822afd3a25841d2dc9cf3562d135a10 [root@localhost ~]# doc Ker Images ReposiTory TAG IMAGE ID CREATED VIRTUAL SIZE MySQL v1 eb81de183cd9 sec Onds ago 281.9 MB Info Display system-wide Information--View Docker System information [Root@localhost ~]# Docker in Fo Containers:3--currently has 3 containers images:298 Storage driver:devicemapper Pool name:docker-253 : 0-34402623-pool pool blocksize:65.54 kB backing filesystem:xfs Data file:/dev/loop0 Me
Tadata file:/DEV/LOOP1 data space used:8.677 GB-corresponds to the following data loop file size data space total:107.4 GB Data space available:5.737 GB Metadata space used:13.4 MB-corresponds to the following Metadata loop file size Metadata Sp Ace total:2.147 GB Metadata space available:2.134 GB Udev Sync supported:true Deferred Removal Enabled:false Data Loop file:/var/lib/docker/devicemapper/devicemapper/data Metadata loop file:/var/lib /docker/devicemapper/devIcemapper/metadata Library version:1.02.93-rhel7 (2015-01-28) Execution driver:native-0.2 Logging Driver:json-file Kernel version:3.10.0-229.el7.x86_64 Operating system:centos Linux 7 (Core) CPUs: 2 Total memory:979.7 MiB Name:localhost.localdomain id:tfvb:bxgq:vvoc:k2dj:lece:2hnk:23b2:levf:p3
IQ:L7D5:NG2V:UKNL Warning:bridge-nf-call-iptables is disabled warning:bridge-nf-call-ip6tables is disabled
Inspect return low-level information on a container or image--for viewing container configuration information, including container name, environment variable, run command, host configuration, network configuration, and data volume configuration.
Kill Kill a running container--forces the container to terminate the difference between stop and Kill, docker the Stop command sends a SIGTERM signal to the process in the container, and the default behavior is to cause the container to exit, of course, A program in a container can capture the signal and handle it itself, for example, optionally ignoring it.
And Docker kill is to send a sigkill signal to the process of the container, the signal will make the container must exit. Load load an image from a tar archive or STDIN--corresponds to the following Save command to import a mirrored image of the following Sava command into the login Register or lo via the Load command G in to a Docker registry--Login to your Docker register, need to have dockER Hub's registered account [root@localhost ~]# Docker login Username:ivictor password:email:xxxx@foxmail. COM warning:login credentials saved In/root/.docker/config.json login succeeded logout Log out from a Docker Registry--Exit login [root@localhost ~]# docker logout Remove login credentials for HTTPS://INDEX.D Ocker.io/v1/logs Fetch The logs of a container--for viewing the container's log, which outputs output to standard output as log output to the Docker logs command's terminal. Often used in the back-end container pause pause all processes within a container-pauses all processes within the container, at which point the resource usage at this time can be observed through Docker stats is fixed
Variable, the further output of the log is not observed through Docker logs-f. Port List port mappings or a specific mapping for the CONTAINER--mapping of output container port to host port for example: [root@local Host ~]# Docker Port blog 80/tcp-> 0.0.0.0:80 container Blog's internal port 80 is mapped to the host's 80 port, which allows you to view the service PS provided by the container blog through the host's 80 ports
List containers-Lists all containers where Docker PS is used to view the running container, and ps-a is used to view all containers. Pull pull an image or a repository From a registry--download a mirror from the Docker hub push push an image or a repository to a registry-upload a local mirror to Docker Hub in the premise that you want to first use Docker login login, otherwise you will report the following error [Root@localhost ~]# Docker push ivictor/centos:v1 the push refer s to a repository [Docker.io/ivictor/centos] (Len:1) unauthorized:access to the requested resource are not Authori Zed Rename rename a container--change the name of the container restart restart a running container--reboot container RM Remove
One or more containers--delete a container, note that you cannot delete a running container, you must first stop it with Docker stop or Docker kill. Of course, you can force the deletion, you must add the-f parameter if you want to remove all containers at once, use Docker rm-f ' Docker ps-a-Q ', where-Q refers to only the ID of the container RMI remove one or more imag ES--Remove mirror Run Run a command in a new container--lets the created container immediately enter the running state, which is equivalent to Docker create container before using Docker The start container save an image (s) to a tar archive-packs the mirrors, as opposed to the above load command, for example: Docker Save-o nginx. Tar Nginx Search Search the Docker Hub for ImagES-search mirror from Docker hub, start one or more stopped containers-boot container stats Display a live str
Eam of container (s) Resource usage statistics-dynamic display of resource consumption of containers, including: CPU, memory, network I/O stop stop a running container --Stop a running container tag tag an image into a repository--Rename the image top Display the running processes of a Container--View the running process in the container unpause unpause all processes within a container--recover the paused process within the container and correspond to the pause parameter ve Rsion Show the Docker version information--View Docker versions wait blocks until a container stops, then print its E
XIT code--When capturing the exit code when a container stops executing this command, the command "hang" at the current terminal until the container stops, at which point the exit code for the container is printed out. Run ' Docker command--help ' For more information on a command.
Thanks for reading, I hope to help you understand and apply the Docker command as soon as possible, thank you for your support to this site!