有用的Docker命令列表以及示例

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
List Docker Commands
List Docker Commands
列出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
run - Run New Container
run – Run New Container
运行–运行新容器

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
pull - Pull A Container Image
pull – Pull A Container Image
拉–拉容器图像

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 .
build - Build Docker Image From Docker File
build – Build Docker Image From Docker File
build –从Docker文件构建Docker映像

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
exec - Run Command In Existing Container
exec – Run Command In Existing Container
exec –在现有容器中运行命令

搜索–在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
search - Search Docker Images In Docker Hub
search – Search Docker Images In Docker Hub
搜索–在Docker Hub中搜索Docker映像

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
commit - Create New Image From Running Container
commit – Create New Image From Running Container
commit –从正在运行的容器中创建新映像
LEARN MORE  How To Use DockerFile To Build Images For Docker Containers?
了解更多信息如何使用DockerFile为Docker容器构建映像?

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值