docker build no such file or directory


 

在我構建新的鏡像的時候, 發生 了  no such file or directory 的錯誤。  這個錯誤找了半天, 沒頭緒, 后來靈光一現, 原來是我的文件夾名字寫錯了

 

我的目錄結構是這樣的

[root@host sample]# find ./ -type f
./enginx/global.conf
./enginx/nginx.conf
./Dockerfile
[root@host sample]# find ./ -type d
./
./enginx
[root@host sample]# 

 

sample 文件夾中有一個Dockerfile 文件和一個nginx文件夾, nginx文件夾中有global.conf  和 nginx.conf

cd 進 sample   下 使用如下命令構建鏡像

[root@host sample]# docker build -t addictions/nginx .

后面的“.”  表示當前目錄, 會從當前目錄去找Dockfile文件, 當前目錄會被上傳到docker進程作為構建上下文目錄,  只有構建上下文目錄的文件才可以被ADD  或者 COPY 到鏡像中。 

 

[root@host sample]# docker build -t addictions/nginx .
Sending build context to Docker daemon 17.41 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu
---> 70d53b6cf65a
Step 1 : MAINTAINER jxl "2013143154@qq.com"
---> Using cache
---> 0be2be8c6d47
Step 2 : ENV REFRESHED_AT 2018-10-21
---> Using cache
---> 48ead1b5bfb6
Step 3 : RUN apt-get -yqq update && apt-get -yqq install nginx
---> Using cache
---> 3c834a6164b3
Step 4 : RUN mkdir -p /var/www/html/website
---> Using cache
---> 5044773f5e09
Step 5 : ADD nginx/global.conf /etc/nginx/conf.d/
nginx/global.conf: no such file or directory

以上是我報的錯, 原因是我我在Dockerfie中的ADD 命令中的文件夾名字寫成了nginx,  而構建上下文目錄中的文件夾是enginx。  不一致, 所以在上下文目錄中找不到這個文件夾, 自然也找不到文件夾下的目錄

 

解決方案:  將構建上下文目錄中的enginx 改成 nginx 即可, 或者將Dockerfile中的ADD 命令后面的nginx 改成enginx,   以下是構建成功之后的輸出

 

[root@host sample]# docker build -t addictions/nginx .
Sending build context to Docker daemon 4.608 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu
 ---> 70d53b6cf65a
Step 1 : MAINTAINER jxl "2013143154@qq.com"
 ---> Using cache
 ---> 0be2be8c6d47
Step 2 : ENV REFRESHED_AT 2018-10-21
 ---> Using cache
 ---> 48ead1b5bfb6
Step 3 : RUN apt-get -yqq update && apt-get -yqq install nginx
 ---> Using cache
 ---> 3c834a6164b3
Step 4 : RUN mkdir -p /var/www/html/website
 ---> Using cache
 ---> 5044773f5e09
Step 5 : ADD nginx/global.conf /etc/nginx/conf.d/
 ---> cfee19df85f2
Removing intermediate container 0eddbc45f54d
Step 6 : ADD nginx/nginx.conf /etc/nginx/nginx.conf
 ---> dbf25a20d66d
Removing intermediate container 8fbdd8c0eb26
Step 7 : EXPOSE 80
 ---> Running in 0e4ef7402519
 ---> 2b909217eb99
Removing intermediate container 0e4ef7402519
Successfully built 2b909217eb99
[root@host sample]# 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM