将Docker映像作为容器运行

本文翻译自:Run a Docker image as a container

I built a Docker image from a dockerfile. 我从dockerfile构建了Docker映像。 I see the image was built successfully, but what do I do with it? 我看到映像已成功构建,但是该如何处理? Shouldn't it be able to run as a container? 它不应该能够作为容器运行吗?


#1楼

参考:https://stackoom.com/question/1Fc5o/将Docker映像作为容器运行


#2楼

The specific way to run it depends on whether you gave the image a tag/name or not. 运行它的具体方法取决于您是否为图像指定了标签/名称。

$ docker images
REPOSITORY          TAG                 ID                  CREATED             SIZE
ubuntu              12.04               8dbd9e392a96        4 months ago        131.5 MB (virtual 131.5 MB)

With a name (let's use Ubuntu ): 使用名称(让我们使用Ubuntu ):

$ docker run -i -t ubuntu:12.04 /bin/bash

Without a name, just using the ID: 没有名称,只需使用ID:

$ docker run -i -t 8dbd9e392a96 /bin/bash

Please see Docker run reference for more information. 请参阅Docker运行参考以获取更多信息。


#3楼

Do the following steps: 请执行以下步骤:

  1. $ docker images

    You will get a list of all local Docker images with the tags specified. 您将获得带有指定标签的所有本地Docker映像的列表。

  2. $ docker run image_name:tag_name

    If you didn't specify tag_name it will automatically run an image with the 'latest' tag. 如果您未指定tag_name ,它将自动运行带有“最新”标签的图像。

    Instead of image_name , you can also specify an image ID (no tag_name). 除了image_name ,您还可以指定图像ID(无tag_name)。


#4楼

Here is an example to run a webdev service in Docker. 这是在Docker中运行Webdev服务的示例。 The image's name is morrisjobke/webdav . 图像的名称是morrisjobke / webdav You can pull it from Docker Hub . 您可以从Docker Hub提取它。

After you run these images, you can then access the WebDAV instance at http://localhost:8888/webdav . 运行这些映像之后,您可以通过http://localhost:8888/webdav访问WebDAV实例。 Internally the folder /var/webdav is used as the WebDAV root. 在内部,文件夹/var/webdav用作WebDAV根目录。

You can run this container in the following way: 您可以通过以下方式运行此容器:

$ docker run -d -e USERNAME=test -e PASSWORD=test -p 8888:80 morrisjobke/webdav

#5楼

  • To list the Docker images 列出Docker映像

     $ docker images 
  • If your application wants to run in with port 80, and you can expose a different port to bind locally, say 8080: 如果您的应用程序要使用端口80运行,并且您可以公开其他端口以本地绑定,请说8080:

     $ docker run -d --restart=always -p 8080:80 image_name:version 

#6楼

You can see your available images using: 您可以使用以下方法查看可用的图像:

docker images

Then you can run in detached mode so your terminal is still usable. 然后,您可以在分离模式下运行,以便您的终端仍然可用。 You have several options to run it using a repository name (with or without a tag) or image ID: 您可以使用存储库名称(带有或不带有标签)或图像ID来运行它的几个选项:

docker run -d repository
docker run -d repository:tag
docker run -d image_id

Then you can check your container is running using 然后您可以使用以下命令检查容器是否正在运行

docker ps

docker ps gives you a container ID. docker ps为您提供了一个容器ID。 You can use it or just the 2/3 first characters to go into your container using: 您可以使用它,也可以只使用前2/3个字符使用以下命令进入容器:

docker exec -it container_id /bin/bash

And you can stop it using docker stop container_id and docker rm container_id . 您可以使用docker stop container_iddocker rm container_id停止它。

You can also run your container with -rm arguments so if you stop your container it will automatically be removed. 您还可以使用-rm参数运行容器,因此,如果停止容器,它将自动被删除。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值