Detailed Docker commands

Source: Internet
Author: User
Tags docker ps docker cp docker hub docker run docker registry

Recently studied Docker, and experimented with all of the Docker commands, with the following special finishing:

# docker--helpusage: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 mo De-h,--host=[] Daemon socket (s) to connect to-h,--help=false Print usage-l,--log -level=info Set The logging level--tls=false use TLS;    Implied by--tlsverify--tlscacert=~/.docker/ca.pem Trust Certs signed only by the This CA--TLSCERT=~/.DOCKER/CERT.PEM Path 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 quitcommands:attach attach to a running container 
--Attaching the terminal to the container 1> running an interactive container [[email protected] ~]# Docker run-i-T CentOS /bin/bash [[email protected]/]# 2> View the status of the container on another window [[EMAIL PR Otected] ~]# Docker ps-a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4a75f165ce6 CentOS "/bin/bash" 5 seconds ago Up 5 Seconds Cranky_mahavira 3> exit the container running in the first step [[email protected]/]# Exi T exit 4> View the status of the container [[email protected] ~]# Docker ps-a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES D4a75f165ce6 CentOS "/bin/bash" 2 minutes ago Exited (0) seconds ago Crank Y_mahavira It can be seen that the state of this container is exited, so how do you run the container again? You can use the Docker Start command 5> to run the container again [[email protected] ~]# Docker start Cranky_mahavira Cranky_mahavira 6> View the status of the container again [[email protected] ~]# Docker ps-a CONTAINER ID IMAGE COMMAND CREATED 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 no specific terminal can interact with it, you can use the Attach command. 7> interact with the Attach command [[email protected] ~]# Docker Attach Cranky_mahavira [[Email&nbs P;protected]/]#
build Build an imageFrom a Dockerfile--Create a mirror from dockerfile
Commit Create anew image from a container ' s changes--Create a local image from a container note: If you are pushing to the Docker hub, note the naming of the generated mirror [[email protected] ~]# Docker commit CENTOS_V1 C ENTOS:V1 68ad49c999496cff25fdda58f0521530a143d3884e61bce7ada09bdc22337638 [[email protected] ~ ]# Docker Push Centos:v1 You cannot push a "root" repository. Please rename your repository to <user>/<repo> (ex: <user>/centos) with CENTOS:V1, because it is push to D Ocker Hub, the user name must be specified when it is pushed to the appropriate user. For example, my username is ivictor, the newly generated local image is named: Docker push Victor/centos:v1, where V1 is tag, not written, default is latest
cp Copy Files/folders from a container to a hostdir or to STDOUT--Copy files between hosts and containers the CP uses the following: Usage:docker CP [OPTIONS] Container:path localpath|- Docker CP [OPTIONS] localpath|-container:path such as:/usr/local/bin/exists docker-entrypoint.sh file in the container MySQL , you can copy to host in the following way
# docker CP Mysql:/usr/local/bin/docker-entrypoint.sh/root
After the modification is complete, copy the file back to the container
# docker cp/root/docker-entrypoint.sh mysql:/usr/local/bin/
Create Create aNew Container
--Create a new container, note that at this point, the status of the container is just created

diff Inspect Changes on a container' s filesystem--View the changed files in the container, take my MySQL container as an example [[email protected] ~]# 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 not difficult See, C corresponds to the directory, a corresponding to the file
Events Get Real Time EventsFrom the server--real-time output of Docker server-side events, including container creation, startup, shutdown, etc. For example: [[email protected] ~]# Docker events 2015-09-08t17:40:13.000000000+08:00 D2a2ef5ddb90b505aca f6b59ab43eecf7eddbd3e71f36572436c34dc0763db79: (from WordPress) Create 2015-09-08t17:40:14.000000000+08:00 D2 a2ef5ddb90b505acaf6b59ab43eecf7eddbd3e71f36572436c34dc0763db79: (from WordPress) Die 2015-09-08t17:42:10.0000 00000+08:00 839866a338db6dd626fa8eabeef53a839e4d2e2eb16ebd89679aa722c4caa5f7: (from MySQL) start
exec Run a commandIn a running container--After the container is started, perform other tasks with the EXEC command to create two tasks: back-end tasks and interactive task background tasks: Docker exec-d cc Touch 123 where CC is the container name Interactive task: [[email protected] ~]# Docker exec-i-t cc/bin/bash [email protected]:/# ls 123 bin Boot Dev etc home lib lib64 media mnt opt proc root run sbin 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 as a tar file: Docker export-o mysqldb1.tar mysqldb Docker export MySQL DB > Mysqldb.tar
History Show The history of an image--show the process of image production, equivalent to Dockfile
Images List Images
--List all mirrors on this machine
Import Import the contentsFrom a tarball to create a filesystem image--Create a new image based on the contents of the tar file, as opposed to the previous Export command [[email protected] ~]# Docker import Mysqldb.tar mysql:v1 eb81d e183cd94fd6f0231de4ff29969db822afd3a25841d2dc9cf3562d135a10 [[email protected] ~]# Docker images R Epository TAG IMAGE ID CREATED VIRTUAL SIZE MySQL V1 eb81de183cd9 seconds ago 281.9 MB
Info Display System-wide Information--View Docker's system information [[email protected] ~]# Docker info containers:3--There are currently 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 Metad ATA 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 fi Le size Metadata space 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 Libra Ry Version:1.02.93-rhel7 (2015-01-28) execution driver:native-0.2 Logging driver:json-file Kernel versio n:3.10.0-229.el7.x86_64 Operating System:centos Linux 7 (Core) cpus:2 Total Memo ry:979.7 MiB Name:localhost.localdomain id:tfvb:bxgq:vvoc:k2dj:lece:2hnk:23b2:levf:p3iq:l7d5: NG2V:UKNL Warning:bridge-nf-call-iptables is disabled warning:bridge-nf-call-ip6tables is DISA Bled
Inspect Return Low-level information on a container or image--Used to view the container's configuration information, including container name, environment variables, Run command, host configuration, network configuration, data volume configuration, and so on.
kill Kill a running container--forcing the container to terminate the difference between stop and kill, the Docker 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, the container program can capture the signal and handle it itself, for example, optionally Select Ignore. Docker Kill is the process of sending a sigkill signal to the container, which will cause the container to exit inevitably.
load load an imageFrom a tar archive or STDIN--In contrast to the following Save command, import the image packaged by the following Sava command into the load command
login Register or logIn to a Docker registry--Login to your Docker register with the Docker hub registered account [[email protected] ~]# Docker login Username:ivictor Password:email: [Email protected] Warning:login credentials saved In/root/.dock Er/config.json Login Succeeded
Logout LogOut from a Docker registry--Sign out [[email protected] ~]# Docker logout Remove login credentials for Https://index.docker.io /v1/
logs Fetch The logs of a container--Used to view the log of the container, which outputs data to the standard output as a log output to the terminal of the Docker logs command. Often used in back-end containers
pause Pause all processes within a container--pauses all processes within the container, at which point the resource usage is fixed by Docker stats, and the further output of the log is not observed through Docker logs-f.
Port List Port mappings or a specific mappingFor the CONTAINER--the mapping of the output container port to the host port for example: [[email protected] ~]# Docker Port blog 80/tcp-0.0.0. 0:80 Internal Port 80 of the container blog is mapped to the host's 80 port, so that the service provided by the container blog can be viewed through the 80 port of the host
PS 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 a image or a repositoryFrom a registry--Download the image from the Docker hub
push push a image or a repository to a registry--Upload the local image to the Docker hub if you want to log in with Docker login first, or you will be reported the following error [[email protected] ~]# Docker push Ivicto R/centos:v1 The push refers to a repository [Docker.io/ivictor/centos] (len:1) Unauthorized:ac Cess to the requested resource are not authorized
Rename rename a container--Change the name of the container
Restart restart a running container
--Restart Container
RM Remove One or more containers--Delete the 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, you can use Docker rm-f ' Docker ps-a-Q ', where-Q refers to only the ID of the container listed
RMI Remove One or more images
--delete Mirror
Run Run a commandIn a newContainer
--Let the container be created immediately into the running state, which is equivalent to Docker create container before using Docker start to start the container
Save save an image (s) to a tar archive--Package The image, as opposed to the above load command, for example: Docker save-o Nginx.tar Nginx
Search Search the Docker HubFor Images
--Search for mirrors from the Docker hub
start start one or more stopped containers--Start container
Stats Display A live stream of container (s) Resource usage statistics--Dynamic display of the resource consumption of the container, including: CPU, memory, network I/O
stop stop a running container
--Stop a running container
tag tag an image into a repository--Renaming the image
top Display The running processes of a container--View the running processes in the container
unpause unpause All processes within a container--Restores the suspended process within the container, as opposed to the pause parameter
version Show the Docker version information
--View the version of Docker
Wait Block until a container stops, then print its exit code-when the capture container stops the exit code executes this command, the command "hang "At the current terminal until the container stops, the exit code for the container is printed. Run ' Docker command--help ' For more information on a command.

Detailed Docker commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.