Detailed Docker commands

Source: Internet
Author: User
Tags docker ps docker cp docker hub docker run docker swarm docker registry
This is a creation in Article, where the information may have evolved or changed.

Order

Docker was installed in the previous Golang development article based on Docker and described how to use Docker for Golang development, and the Docker commands are explained in this article.

View Docker commands

➜TONNY@TONNY-PC ~ Docker-husage:docker [OPTIONS] COMMAND [arg ...] Docker [--help |-v |--version]a self-sufficient runtime for containers. Options:--config=~/.docker location of client config files-d,--debug Enable debug mo De-h,--host=[] Daemon socket (s) to connect to-h,--help Print usage-l,--log -level=info Set The logging level--TLS 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 use  TLS and verify the Remote-v,--version Print version information and Quitcommands:attach attach To a running container build build a image from a Dockerfile commit Create a new image from a container ' s C Hanges cp Copy FileS/folders between a container and the local filesystem create Create a new container diff Inspect changes on A container ' s filesystem events Get real time events from the server exec Run a command in a running Contai NER Export export a container ' s filesystem as a tar archive history Show The history of an image images L IST images Import Import the contents from a tarball to create a filesystem image info Display system-wide i nformation inspect Return low-level information on a container, image or task kill kill one or more running C    Ontainer load load an image from a tar archive or STDIN login Log on to a Docker registry.    Logout Log out from a Docker registry. Logs Fetch the logs of a container network Manage Docker networks node Manage Docker Swarm nodes Paus e Pause all processes within one or more containers port List ports mappings or a specific mapping forThe container PS List containers pull pull a image or a repository from a registry push push Image or a repository to a registry rename rename a container Restart restart a container RM Remove One or more containers rmi Remove One or more images run run a command in a new container save S Ave One or more images to a tar archive (streamed to STDOUT by default) search search the Docker Hub for images s Ervice Manage Docker Services start start one or more stopped containers stats Display a live stream of CO    Ntainer (s) Resource usage statistics stop stop one or more running containers swarm Manage Docker swarm Tag tag an image into a repository top Display the running processes of a container unpause unpause al L processes within one or more containers update update for configuration of one or more containers version Show th E Docker version Information Volume Manage docker volumes wait Block until a container stops, then print its exit Coderun ' Docker CO Mmand--help ' For more information on a command.

Attach attach to a running container
--Attaching the terminal to the container

  1. Run an interactive container
    [root@localhost ~]# docker run -i -t centos /bin/bash [root@f0a02b473067 /]#
  2. View the status of the container on another window
    [root@localhost ~]# 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
    [root@d4a75f165ce6 /]# exit exit
  4. View the status of the container
    "' Bash
    [Root@localhost ~]# Docker Ps-a
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    D4a75f165ce6 CentOS "/bin/bash" 2 minutes ago Exited (0) seconds ago Cranky_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. Run the container again
    [root@localhost ~]# docker start cranky_mahavira cranky_mahavira
  6. View the status of the container again
    [root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d4a75f165ce6 centos "/bin/bash" 6 minutes ago Up 29 seconds cranky_mahavira
    Because the container is interactive, we can now use the Attach command when we find that no specific terminal can interact with it.
  7. Interacting with the Attach command
    [root@localhost ~]# docker attach cranky_mahavira [root@d4a75f165ce6 /]#

Build Build an image * *from a Dockerfile * *
--Create a mirror from dockerfile

Commit Create A * *new image from a container ' s changes**
--Create a local mirror from a container

Note: If you want to push to the Docker hub, be aware of the naming of the generated mirror.

[root@localhost ~]# docker commit centos_v1 centos:v168ad49c999496cff25fdda58f0521530a143d3884e61bce7ada09bdc22337638 [root@localhost ~]# docker push centos:v1 You cannot push a "root" repository. Please rename your repository to <user>/<repo> (ex: <user>/centos)

Not with CENTOS:V1, because when it pushes to the Docker hub, it is pushed to the appropriate user and the user name must be specified. For example, my user name is Ivictor, the newly generated local image is named: Docker push Victor/centos:v1, where V1 is tag, can not be written, the default is latest.

CP Copy file/folders from a container to a hostdir or to STDOUT
--Copy files between host and container

The use of CP is as follows:

Usage: docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|- docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH

Create Create a new 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
--look at the changed files in the container, take my MySQL container as an example

Events Get Real time event from the server--realtime output Docker server-side incidents, including container creation, startup, shutdown, etc.

exec Run A command in a running container
--To perform other tasks after the container is started

The EXEC command allows you to create two kinds of tasks: back-end tasks and interactive tasks

#后台型任务:[root@localhost ~]#docker exec -d cc touch 123 #其中cc是容器名 #交互型任务: [root@localhost ~]# docker exec -i -t cc /bin/bash root@1e5bb46d801b:/# 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
--Package The container's file system into a tar file

There are two ways of doing this:

[root@localhost ~]# docker export -o mysqldb1.tar mysqldb [root@localhost ~]# docker export mysqldb > 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 contents * *from 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

Info Display system-wide Information
--View Docker's system Information

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
--Forced termination of the container

With regard to 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 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 image from 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 log in to a Docker registry --Log into your Docker register and need a registered account for the Docker hub

Logout logout from a Docker registry
--Sign Out

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 mapping for the CONTAINER
--mapping of the output container port to the host port

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, an image, or a repository from 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 report an error.

Rename Rename a container
--Change the name of the container

Restart restart a running container
--Restart Container

RM Remove one or more containers
--Delete 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 delete 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 command in a new container
--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 load command above

Search Search the Docker Hub for 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
--Resumes the process of pausing 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
--Capture the exit code when the container stops

After executing this command, the command will "hang" at the current terminal until the container stops and the exit code for the container will be printed.

Related Article

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.