gpt4 book ai didi

docker - Dockerfile中的命令将按以下方式运行吗?

转载 作者:行者123 更新时间:2023-12-02 19:35:32 26 4
gpt4 key购买 nike

docker build Dockerfile .//running it correctly.

1.)我在注释中提到了每个命令都将按照书面执行,这是Dockerfile的正确工作吗?

2)这些命令将在我运行docker build时用于制作镜像,因此

[ec2-user @ ip-xx-xx-xx-xx〜] $ cd / project / p1

[ec2-user @ ip-xx-xx-xx-xx p1] $ ls

Dockerfile a b c d

我的Dockerfile由以下命令组成。

Dockerfile
node 8.1.0 //puls the image from hub

RUN mkdir -p /etc/x/y //make directory in the host at path /etc/x/y

RUN mkdir /app //make directory in the host at path /app

COPY . /app //copy all the files that is
WORKDIR /app //cd /app; now the working directory will be /app for next commands i.e npm install.

RUN npm install

EXPOSE 3000 //what this will do?

最佳答案

问题1:如何运行docker build?

docker build Dockerfile . # am I running it correctly.

不,您可以使用 docker build .运行它,而docker会自动在当前目录中查找 Dockerfile。或者,您使用 docker build -f Path_to_the_docker_file/DockerFile,在其中明确指定 DockerFile的路径。

问题2:修正错误并澄清命令

Dockerfile 中几乎没有错误,请检查编辑后的注释:
# 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.

关于docker - Dockerfile中的命令将按以下方式运行吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45658173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com