43

I want to deploy a simple JS Boilerplate to Docker Cloud. I use a Dockerfile that I already used for a different Boilerplate and image. The Dockerfile is pretty simple. It is just based on the official nginx, adds two config files and then the output folder of my gulp boilerplate to the nginx root. So I copied it from the one directory to the new boilerplate since I want to try this one.

The error I'm getting is this (last line)

Sending build context to Docker daemon 277.5 kB
Step 1 : FROM nginx
 ---> af4b3d7d5401
Step 2 : MAINTAINER Ole Bjarnstroem
 ---> Using cache
 ---> f57bc23d9444
Step 3 : ENV LANG en_US.UTF-8
 ---> Using cache
 ---> f6f4a76092dd
Step 4 : COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
 ---> Using cache
 ---> c4f83a39ba73
Step 5 : COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
 ---> Using cache
 ---> 6fe5a6b61d9f
Step 6 : ADD ./dist /usr/share/nginx/html
lstat dist: no such file or directory

But the dist folder is there.

.
├── Dockerfile
├── JSCS.intellij.formatter.xml
├── README.md
├── app
├── dist
├── gulpfile.babel.js
├── jspm.conf.js
├── jspm_packages
├── karma.conf.js
├── nginx
├── node_modules
├── package.json
├── tsconfig.json
├── tslint.json
├── typings
└── typings.json

It might be noteworthy that the folder to be copied was called ./public So I could imagine that this is some kind of weird Docker Cache issue.

My Dockerfile:

FROM nginx

ENV LANG en_US.UTF-8

# Copy configuration files
COPY ./nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf

# Add Gulp output folder to server root
ADD ./dist /usr/share/nginx/html

# Port configuration
EXPOSE 8080

What I tried so far:

  • Deleting dangling and unused images
  • Deleting the image that was produced by the same docker file before
  • Using a different tag

My build command:

docker build -t my_repo/my_app .

Thanks for your help!

Edit: Every other folder works. It is also not a problem of file permissions. It seems, that Docker just doesn't like the dist folder. Which sucks.

Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160

10 Answers10

101

Well, stupid me. There was a .dockerignore file with dist in the project folder... Case closed

Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
  • 3
    I just did this. Wondered why my .rpm wasn't getting ADDed. It all became clear (after reading this) when I realised I had *.rpm in .dockerignore. Thanks. – Chris Mar 24 '16 at 10:27
  • 2
    this answer already helped me once some time ago; I then had to google this again today, and there were actually no records in `.dockerignore` for the folder I tried to add... then I've found a typo in a folder's name :\ – Dmitry Gusev Sep 28 '16 at 14:45
  • 6
    Doh!!! I struggled on this issue for hours, thanks for posting this else I would have been lost. My stupidity went even further I had * in .dockerignore :( – Daya Sharma Oct 28 '16 at 19:01
  • 4
    Docker could really emit a better error message here. – jcollum Mar 27 '17 at 16:00
  • Same thing just happened to me. Deleted the .dockerignore file I forgot I created and it worked. – camccar Apr 10 '17 at 20:42
  • 2
    this is why we have no life. – Zein Miftah Oct 09 '17 at 08:39
  • Seems like you're not alone ! – amit Nov 03 '17 at 14:25
17

I had the same issue, but it wasn't the .dockerignore, I forgot to specify the directory to run docker in. In my case that directory was . My full command before was

docker build - < Dockerfile

and after was

docker build . < Dockerfile
Nadjib Mami
  • 5,736
  • 9
  • 37
  • 49
Rich
  • 658
  • 1
  • 9
  • 18
7

I put the directory after the build command used -f to specify the dockerfile

eg:

sudo docker build . -t test:i386 -f mydockerfile

The dot after build is the directory to build from, in this case present dir.

Vijay47
  • 337
  • 5
  • 13
4

I also had the same issue, the problem wasn't my .dockerignore but my .gitignore, as I couldn't remove dist from my gitgnore I've added cp command in my Dockerfile:

....
WORKDIR /
RUN cp -r public/dist/* www/
EXPOSE 80
3

(credits: https://serverfault.com/a/666154/152918)

The files you want to copy must be inside the Docker image directory. You cannot reference files anywhere on your file system.

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
2

I had this issue, and the problem turned out to be that I had inlined a comment, e.g.

COPY file1.txt dest/ # comment

Turns out you can't do that.

George Dewar
  • 103
  • 7
1

A related bug in the Google App Engine SDK version 138 resulted in the same error message. This bug has been fixed in version 139 of the SDK. You can upgrade to the newest version with the following command:

gcloud components upgrade
speedplane
  • 15,673
  • 16
  • 86
  • 138
0

For following docker build error,

COPY failed: stat /<**path**> :no such file or directory

I got it around by restarting docker service.

sudo service docker restart
Vineeth
  • 692
  • 3
  • 9
  • 18
0

A bit about how I got this error: I was running in gitlab-ci, and I git this in the logs:

enter image description here

And so when I got to the stage where I run docker build, there was no Dockerfile in there, so I got this error.

There are two ways to solve it:

  1. You can setup somewhere in the project settings to use git strategy of fetch/clone. Im not sure which setting it is - so play around until you get it. This will configure the git strategy for the entire project.

  2. You can also setup git strategy just for the build - you can add a variable like this in the top of your gitlab-ci.yml file:

variables:
  GIT_STRATEGY: clone

And it should solve it.

Alon Gouldman
  • 3,025
  • 26
  • 29
0

On Mac OS Big Sur I had to just restart my Docker Service then worked again for me(Always happens after changing my .env)

markokoen
  • 29
  • 3