Docker command line entry Daquan: This 18, you may not know

There are tens of millions of Docker command line. Therefore Docker document is rich in content, while letting the novice just getting started to feel overwhelmed. In this article, I will focus on the key command to run Docker's.

 

Foreword

 

Docker Dockerfile mirror is necessary and the composition dependencies, dynamic Docker Docker container mirror. To use the Docker command, you first need to know that you are dealing with a mirror or container. Once you know what you are dealing with a mirror or container After that, you can find the right command.

 

Common commands

 

You need to know some rules about Docker command:
 

  • Docker CLI management commands that begin with docker, then a space, followed by management category, followed by a space and finally the command. For example, docker container stop command to stop the vessel.

  • Reference a particular container or the container need mirror or mirror command name or ID.
     

For example, docker container run my_app commands for building and running named my_app container. In the example in this article, I will use the name to refer to my_container generic container. Similarly, my_image, my_tag as well.

 

I alone will provide command and general signs. There are two signs in front of the dash is the full name logo. Mark with a dash sign is the abbreviation for the full name. For example, -p is an abbreviation --port flag.

 
Goal of this article is to get you to keep in mind these commands and markers, and hope that you can when you create or build a container can be mirrored in this guide as a reference. This guide is for Linux and Docker Engine API version 1.39 and version 18.09.1.

 

We first understand the vessel command and then look at the mirror command.
 

Docker command line entry Daquan: This 18, you may not know
 

Container command

 

使用 docker container my_command

 

  • create - Create a container from the mirror

  • start - start an existing container

  • run - to create a new container and start it

  • ls - list the container is running

  • inspect - view information about the container

  • logs - Print Log

  • stop - stop the container elegant running

  • kill - to immediately stop the main process vessel

  • rm - delete has stopped container
     

    Mirroring Command

     

Use docker image my_command

 

  • build - Construction of a mirror

  • push - push the remote mirror image repository

  • ls - list Mirror

  • history - view mirror information center

  • inspect - view information about the image, including layers

  • rm - remove a mirror
     

    Container & Mirror

     

  • docker version - Lists information about Docker client and server versions

  • docker login - log on to the Docker image warehouse

  • docker system prune - delete all unused containers, the name of the network, and no mirror (mirror dangling)
     

    Container command Detailed

     

Start container

 

The term "Create", "start" and "run" in everyday life have similar semantics, but each is an independent Docker commands for creating and / or starting container. Let's take a look at command to create a container.

 

docker container create my_repo / my_image: my_tag - Create a mirror from container
 

In the following I will put my_repo / my_image: my_tag abbreviated my_image.

 

You can create by passing a number of flags.

 

docker container create -a STDIN my_image

 

-a is -attach acronym refers to connecting the container to STDIN, STDOUT or STDERR.

 

Now that we have created a container, so let's start it.

 

docker container start my_container - start an existing container

 

Please note that the container can be referenced by name or ID of the container vessel.

 

docker container start my_container

 

Now that you know how to create and start a container, let's look at the most common Docker command. It will create and start combined into one command: run.

 

docker container run my_image - create a new container and start it. The command also has many options. Let's look at a few.

 

docker container run -i -t -p 1000:8000 --rm my_image

 

-i is -interactive Abbreviation, even when not connected, but also to maintain open STDIN; -t is an abbreviation of -tty, it allocates a pseudo-terminal, a terminal to connect the container STDIN and STDOUT.

 

You need to specify the -i and -t through interaction with the container terminal shell.

 

-port -p is an abbreviation of. Port is an interface with the outside world. 1000: 8000 Docker maps port 8000 to port 1000 on the computer. If you have an app output some content to the browser, you can set your browser to navigate to localhost: 1000 and see it.

 
--rm deleted automatically stop running container.

 
Let's look at a few examples of the run.

 
docker container run -it my_image my_command

 
sh you can specify at runtime command shell session will start inside the container, you can interact with through the terminal. For the Alpine mirror, sh than bash, since the image is not Alpine installed together with bash. Type exit to end an interactive shell session.

 

Please note that we will combine -i and -t to -it.
 

docker container run -d my_image

 

-d is -detach acronym refers to the vessel running in the background, allowing you to run the container terminal will be used for other commands.
 
Docker command line entry Daquan: This 18, you may not know
 
Check the container status
 

If you have a lot of running Docker container and with which you want to find an interactive, then you need to list them.
 

docker container ls - list the container operation, while providing useful information about the container.

 

docker container ls -a -s

 

-a --all is the abbreviation of listing all containers (containers not only the running)
 
-s is -size abbreviation lists the size of each container.
 

docker container inspect my_container - View information about the container

 

docker container logs my_container - listed container logs

 

Termination container
 

Sometimes you need to stop running in a container, you need to use the following command:

 

docker container stop my_container — 优雅地停止一个或多个正在运行的容器。在容器关闭之前提供默认10秒以完成任何进程。
 

如果你觉得10秒太长的话,可以使用以下命令:

 

docker container kill my_container — 立即停止一个或多个正在运行的容器。这就像拔掉电视上的插头一样。但是在大多数情况下,建议使用stop命令。

 

docker container kill $(docker ps -q)— 终止所有运行中的容器
 

你需要删除容器可以使用以下命令:
 

docker container rm my_container — 删除一个或多个容器
 
docker container rm $(docker ps -a -q) — 删除所有不在运行中的容器

 

以上就是Docker容器的关键命令。接下来,我们来看看关于镜像的命令。

 

镜像命令详解

 

以下是Docker镜像使用的7条命令

 

构建镜像

 

docker image build -t my_repo/my_image:my_tag . 在指定路径或url的Dockerfile中构建一个名为my_image的Docker镜像。

 

-t是tag的缩写,是告诉docker用提供的标签来标记镜像,在本例中,是my_tag。

 

在命令末尾的句号(.)是告诉Docker根据当前工作目录中的Dockerfile构建镜像。

 

当你构建好镜像之后,你想要推送它到远程仓库中以便它可以共享并且在有需要的时候被拉取。那么下一个命令十分有用,尽管并非是镜像命令。

 

docker login — 登录到Docker镜像仓库,根据提示键入你的用户名和密码

 

docker image push my_repo/my_image:my_tag — 推送一个镜像到仓库。

 

你拥有了这些镜像之后,你可能想要检查他们。

 
Docker command line entry Daquan: This 18, you may not know
 
检查镜像

 

docker image ls — 列出你的镜像以及每个镜像的大小

 

docker image history my_image - intermediate mirrored image display, including the size and how to create

 

docker image inspect my_image - Display details about the mirror, the mirror layers including

 

Sometimes you need to clean your mirror.

 

Clean up image

 

docker image rm my_image - delete the specified image. If the image is stored in a warehouse in the mirror, then the mirror is still available there.

 

docker image rm $ (docker images -a -q) - delete all images. Care must be taken to use this command. Note has been pushed to the remote repository mirroring still be able to save, which is an advantage mirrored warehouse.
 

These are the most important commands related to Docker image.
 

To see the CLI reference when using Docker, simply enter the command docker to the command line. Docker document see:

https://docs.docker.com/engine/reference/commandline/cli/

 

Now that you have mastered the key command to run Docker, you can build things with Docker! Quickly get started operation it!

Guess you like

Origin blog.51cto.com/12462495/2434641