Dockerfile中的命令是否按如下方式运行?
1.)我在评论中提到,每个命令都将以书面形式执行,该Dockerfile的工作是否正确 2.)当我运行docker build时,这些命令将用于生成图像,因此 [ec2-user@ip-xx xx xx~]$cd/project/p1 [ec2-user@ip-xx xx xx p1]$ls Dockerfile a b c d 我的Dockerfile由以下命令组成 DockerfileDockerfile中的命令是否按如下方式运行?,docker,dockerfile,Docker,Dockerfile,1.)我在评论中提到,每个命令都将以书面形式执行,该Dockerfile的工作是否正确 2.)当我运行docker build时,这些命令将用于生成图像,因此 [ec2-user@ip-xx xx xx~]$cd/project/p1 [ec2-user@ip-xx xx xx p1]$ls Dockerfile a b c d 我的Dockerfile由以下命令组成 Dockerfile docker build Dockerfile .//running it correctly. 问题1
docker build Dockerfile .//running it correctly.
问题1:如何运行docker build?
不,您使用docker build运行它。
docker将自动在当前目录中查找Dockerfile
。或者使用docker build-f Path\u来\u docker\u文件/DockerFile
,在这里您可以清楚地指定DockerFile
的路径
问题2:修复错误和澄清命令
Dockerfile中几乎没有错误,请检查编辑的注释:
docker build Dockerfile . # am I running it correctly.
是的,它从上到下运行。Expose会打开同一网络上其他容器的端口,但不会打开主机。但是我在主机上找不到/app目录,并且映像也是为此而生成的。嗯,
app
目录是在容器中创建的,它复制了生成映像所用文件夹中的所有数据。这是因为您使用了复制/app
这几乎意味着“将当前文件夹中的所有内容复制到containers/app目录”。对。主机是计算机,但是在你写的注释中,make目录位于主机的path/app
,这不是发生的事情。如果您在映像中运行mkdir/app,它将为容器而不是主机创建一个目录。我猜您甚至在运行build命令之前就已经拥有了该文件夹。
docker build Dockerfile . # am I running it correctly.
# pulls the image from dockerhub : YES
# Needs to be preceeded with FROM
FROM node 8.1.0
# all directories are made inside the docker image
# make directory in the image at path /etc/x/y : YES
RUN mkdir -p /etc/x/y
# make directory in the image at path /app : YES
RUN mkdir /app
COPY . /app # copy all the files that is : YES
WORKDIR /app # cd /app; now the working directory will be /app for next commands i.e npm install. : YES
RUN npm install
EXPOSE 3000 # what this will do? => tells all docker instances of this image to listen on port 3000.