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。)我在评论中提到每个命令都会按照写入的方式执行,这个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
rides = [
{ driver_id: "DR0004", date: "3rd Feb 2016", cost: 5, rider_id: "RD0022", rating: 5 },
{ driver_id: "DR0001", date: "3rd Feb 2016", cost: 10, rider_id: "RD0003", rating: 3 },
{ driver_id: "DR0002", date: "3rd Feb 2016", cost: 25, rider_id: "RD0073", rating: 5 },
{ driver_id: "DR0004", date: "3rd Feb 2016", cost: 5, rider_id: "RD0022", rating: 5 },
]
rides.each_with_object({}) do |ride, h|
h.update(ride[:driver_id]=>{ rides: 1, earnings: ride[:cost] }) do |_,o,n|
{ rides: o[:rides]+1, earnings: o[:earnings]+n[:earnings] }
end
end
#=> {"DR0004"=>{:rides=>2, :earnings=>10},
# "DR0001"=>{:rides=>1, :earnings=>10},
# "DR0002"=>{:rides=>1, :earnings=>25}}
答案 0 :(得分:1)
docker build Dockerfile . # am I running it correctly.
不,您使用docker build .
运行它,docker会自动在当前目录中查找Dockerfile
。或者您使用docker build -f Path_to_the_docker_file/DockerFile
清楚指定DockerFile
的路径。
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.