Docker is an emerging technology used mainly by developers and system administrators. I provides the flexibility to run different environments with little system overload and resources. In this tutorial we will learn basic but useful Docker commands with examples.
Docker是一种新兴技术,主要供开发人员和系统管理员使用。 我提供了在很少的系统过载和资源的情况下运行不同环境的灵活性。 在本教程中,我们将通过示例学习基本但有用的Docker命令。
列出Docker命令 (List Docker Commands)
We generally need to list provided commands to remember or learn. We can list existing Docker commands by running docker
command like below.
我们通常需要列出提供的命令以记住或学习。 我们可以通过运行列出现有的码头工人命令docker
像下面的命令。
$ docker

运行–运行新容器(run – Run New Container)
Now we will start with a basic command which will start a container in daemon mode. The default behavior of Docker is running given container and stopping it. We can run in daemon mode with run
command like below.
现在,我们将从一个基本命令开始,该命令将以守护程序模式启动一个容器。 Docker的默认行为是运行给定的容器并停止它。 我们可以使用以下run
命令在守护程序模式下run
。
$ sudo docker run -t -i ubuntu bash

start –启动已停止的容器(start – Start Stopped Container)
start
command will start all ready created but stopped container. In this example we will start container named test
start
命令将启动所有已创建但已停止的容器。 在此示例中,我们将启动名为test
容器
$ sudo docker start test
停止–停止运行容器 (stop – Stop Running Container)
stop
command will stop all ready created but started container. In this example we will stop container named test
stop
命令将停止所有已创建但已启动的容器。 在此示例中,我们将停止名为test
容器
$ sudo docker stop test
拉–拉容器图像 (pull – Pull A Container Image)
Docker images provide required files, libraries and system files. We can create them by building Docker image or pulling from registers. Docker hub is open source register used by default. We can get an image from Docker Hub with pull
command. In this example we will pull ubuntu
image like below.
Docker映像提供必需的文件,库和系统文件。 我们可以通过构建Docker映像或从寄存器中提取来创建它们。 Docker Hub是默认使用的开源寄存器。 我们可以使用pull
命令从Docker Hub获取映像。 在此示例中,我们将拉下ubuntu
图像,如下所示。
$ sudo docker pull ubuntu

build –从Docker文件构建Docker映像(build – Build Docker Image From Docker File)
Docker images generally pulled from registry. But we can also create Docker image with defined configuration. We create some Docker File which provides build information like which based image will be used, which users, files will be create or packages will be installed. We can create image like below. run build
command while current working directory is Docker file path.
Docker映像通常是从注册表中提取的。 但是我们也可以使用定义的配置创建Docker映像。 我们创建了一些Docker File,它提供了构建信息,例如将使用哪个基于映像的图像,将创建哪些用户,文件或将安装软件包的信息。 我们可以创建如下图像。 当前工作目录为Docker文件路径时运行build
命令。
$ sudo docker build .

exec –在现有容器中运行命令(exec – Run Command In Existing Container)
exec
is very popular command because it runs commands in all ready running Container . We just provide the command we want to execute in given container. In this example we will run whoami
command in the container. We will provide the container id and the command.
exec
是非常流行的命令,因为它在所有准备运行的Container中运行命令。 我们只提供要在给定容器中执行的命令。 在此示例中,我们将在容器中运行whoami
命令。 我们将提供容器ID和命令。
$ sudo docker exec a59e88993206 whoami

搜索–在Docker Hub中搜索Docker映像(search – Search Docker Images In Docker Hub)
While creating Container environment we generally need a lot of prebuilt Container images. We can search for them in Docker Hub with search
command like below.
在创建容器环境时,我们通常需要大量预先构建的容器映像。 我们可以使用如下search
命令在Docker Hub中进行search
。
$ sudo docker search suricata

commit –从正在运行的容器中创建新映像(commit – Create New Image From Running Container)
Another popular scenario in Docker usage is changing and putting data in some containers and saving this containers for future use without losing data. As we know changes made in container will lost after stop. So we will commit them by using their container ID and the new name we want to use.
Docker使用中的另一个流行场景是更改数据并将其放入某些容器中,并保存此容器以备将来使用而不会丢失数据。 众所周知,容器中所做的更改将在停止后丢失。 因此,我们将使用其容器ID和我们要使用的新名称来提交它们。
$ sudo docker commit a59e88993206 mynewcontainer

翻译自: https://www.poftut.com/useful-docker-command-list-with-examples/