Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build from Dockerfile shows "ADD failed - No such file or directory"

Tags:

docker

nginx

When I try to build the following (simple) NGINX docker container https://github.com/MarvAmBass/docker-nginx-ssl-secure, it always fails with the following error: stat /var/lib/docker/tmp/docker-builder00Whatever/basic.conf: no such file or directory

My directory looks like this:

├── basic.conf
├── Dockerfile
├── entrypoint.sh
├── LICENSE
├── README.md
└── ssl.conf

Running the command sudo docker build - < Dockerfile as root user doesn't change a thing. Does anyone have a solution here?

like image 797
FranzHuber23 Avatar asked Feb 24 '18 17:02

FranzHuber23


People also ask

What is add file in Dockerfile?

The ADD command is used to copy files/directories into a Docker image. It can copy data in three ways: Copy files from the local storage to a destination in the Docker image. Copy a tarball from the local storage and extract it automatically inside a destination in the Docker image.

Does Workdir in Dockerfile create a directory?

If the WORKDIR command is not written in the Dockerfile, it will automatically be created by the Docker compiler. Hence, it can be said that the command performs mkdir and cd implicitly. If the project directory does not exist, it will be created.

Does Dockerfile need Workdir?

According to the documentation: The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn't exist, it will be created even if it's not used in any subsequent Dockerfile instruction.


3 Answers

Ok, for me it worked to use docker build . -f Dockerfile instead of docker build - < Dockerfile (which was the suggestion from the offical docker documentation by the way: https://docs.docker.com/engine/reference/commandline/build/#tarball-contexts). The solution was taken from github: https://github.com/moby/moby/issues/34986#issuecomment-343680872

like image 97
FranzHuber23 Avatar answered Sep 19 '22 23:09

FranzHuber23


The most common causes of this issue are:

  1. Incorrect path

  2. Having docker-builder in your .dockerignore

like image 26
ginna Avatar answered Sep 19 '22 23:09

ginna


I found the same error message when I used docker-compose.yml with follows directory structure. I fixed it by updating the dockerfile path in the docker-compose.yml as follows.

.docker      
├── basic.conf
├── Dockerfile

My docker-compose.yml look like this when I found the error

services:
  web:
    build:
      context: ./
      dockerfile: .docker/nginx

I have solved the problem by update the docker-compose.yml as follows.

services:
  web:
    build:
      context: ./
      dockerfile: .docker/nginx/Dockerfile
like image 20
Khachornchit Songsaen Avatar answered Sep 21 '22 23:09

Khachornchit Songsaen