简体   繁体   English

从 Dockerfile 创建镜像

[英]Create an image from a Dockerfile

I am looking at a Docerfile like this:我正在查看这样的 Docerfile:

FROM microsoft/aspnetcore:2.0 AS base

# Install the SSHD server
RUN apt-get update \
  && apt-get install -y --no-install-recommends openssh-server \
  && mkdir -p /run/sshd \
  && echo "root:Docker!" | chpasswd
#Copy settings file. See elsewhere to find them. 
COPY sshd_config /etc/ssh/sshd_config
COPY authorized_keys  root/.ssh/authorized_keys

# Install Visual Studio Remote Debugger
RUN apt-get install zip unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg

EXPOSE 2222

I am trying to create an image using this dockerfile.我正在尝试使用此 dockerfile 创建图像。 How can I do this?我怎样才能做到这一点? I have read many webpages over the last few hours eg this one https://odewahn.github.io/docker-jumpstart/building-images-with-dockerfiles.html , however they all seem to overcomplicate it as my research is telling me that there is only one command needed.在过去的几个小时里,我阅读了许多网页,例如这个https://odewahn.github.io/docker-jumpstart/building-images-with-dockerfiles.html ,但是正如我的研究告诉我的那样,它们似乎都过于复杂了只需要一个命令。

If Dockerfile is in your current directory, this command will build image and store it locally:如果Dockerfile在您的当前目录中,此命令将构建镜像并将其存储在本地:

docker build -t "app:latest" .

Here is documentation for build command 这是build命令的文档

Then you can run it in background with:然后你可以在后台运行它:

docker run -d -p 2222:2222 app

This command will create container and start it.此命令将创建容器并启动它。 Here is documentation for run command .这是run命令的文档

I'm not really sure what you consider 'overcomplicated' on that website?我不确定您认为该网站上的“过于复杂”是什么?

There's one command on that site that says docker build -t "simple_flask:dockerfile" .该站点上有一个命令说docker build -t "simple_flask:dockerfile" . . . The only complication is that it adds a tag, which is explained directly underneath it唯一的复杂之处在于它添加了一个标签,在其正下方进行了解释

The only thing that might be simpler is not tagging it.唯一可能更简单的是不标记它。 so you do所以你也是

docker build .

which means: build me an image.这意味着:为我建立一个形象。 from the current directory.从当前目录。

Since you have a Docker file, you are required to do 4 additional steps:由于您有一个 Docker 文件,您需要执行 4 个额外的步骤:

  1. docker build -t <app-name> . : Building your image : 建立你的形象

  2. docker images : Check your image docker images :检查您的图像

  3. docker run -d -p 2222:8080 myapp : Run your image docker run -d -p 2222:8080 myapp :运行你的镜像

  4. docker ps : Check running docker image docker ps : 检查正在运行的 docker 镜像

Refer Docker doc.请参阅Docker 文档。 for more detials了解更多详情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM