Dockerfile error with ADD command "/ADD" not found: not found"

Hi I have a an issue when I try to build a nginx server by using the commands within the following Dockerfile. I get an error which is failed to compute cache key: "/ADD" not found: not found. It happens when I try to uncompress the tar file with the ADD command. I run the build command docker build --tag local:dockerfile-example . . How would I be able to fix this?

Contents of the Dockerfile:

FROM alpine:latest

LABEL "website.name"="geeksforgeeks website"

LABEL "website.tutorial-name"="docker"

RUN apk add --update nginx && \

rm -rf /var/cache/apk/* && \

mkdir -p /tmp/nginx/

COPY files/nginx.conf /etc/nginx/nginx.conf

COPY files/default.conf /etc/nginx/conf.d/default.conf ADD files/html.tar.gz /usr/share/nginx/

EXPOSE 80/tcp

ENTRYPOINT [“nginx”]

CMD [“-g”, “daemon off;”]

Directory:

.
├── files/
│   ├── default.conf
│   ├── html.tar.gz
│   └── nginx.conf
└── Dockerfile

Seems like you accidently forgot to add a new line before the ADD instruction.
Instead of:

COPY files/default.conf /etc/nginx/conf.d/default.conf ADD files/html.tar.gz /usr/share/nginx/

It needs to be:

COPY files/default.conf /etc/nginx/conf.d/default.conf
ADD files/html.tar.gz /usr/share/nginx/
1 Like

yea it was a silly mistake thank you for pointing that out.

Since that problem was solved I encountered another one, if you could help with that also I would appreciate ıt:
So after the image is build by executing the command docker build --tag local:dockerfile-example . I try to run the docker container with the following command docker container run -d --name dockerfile-example -p 8080:80 local:dockerfile-example. I check the status of the container with docker ps and it is not visible although when I run docker ps -a. I see the container information I see that the port alignment is not visible 8080:80. I am running on macSO Montrey. Would you know how I can fix this issue?

output for running docker ps -a :

CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS                        PORTS     NAMES
8a4002581729   local:dockerfile-example   "/bin/sh -c [“nginx”…"   20 seconds ago   Exited (127) 19 seconds ago             dockerfile-example

Have checked the container logs? They might indicate why the container terminated.

It looks like the ENTRYPOINT [“nginx”] in the dockerfile is causing the issue

docker logs output:

bin/sh: line 0: [“nginx”]: not found

The doube quotes look off. Your LABEL instructions use correct double quotes, while your ENTRYPOINT and CMD does not. You might want to fix that and try again.

I have changed it yet it still doesnt work, Im researching it. It also gives the same log error.

hmm, doesn’t realy make sense, as nginx is installed as alpine package and should be in the path.

Just out of curiousit: have you considered to use the official nginx image as base image? It has tags for an alpine flavor and has a rather nice entrypoint script that allows to add custom scripts and even provides a simple templating engine.

update: I am afraid something is off with the encoding of these lines:

ENTRYPOINT [▒~@~\nginx▒~@~]]
CMD [▒~@~\-g▒~@~], ▒~@~\daemon off;▒~@~]]

I copy/pasted your Dockerfile content into a file using vi and this is what I see. please type those lines again in an editor like vscode or an ide like intellij.

Oh I am new docker and linux images in general. I was using a dockerfile that was created from this tutorial book that I was using. I could possibly try that but I will have to sort the dockerfile image and learn about it.
I have changed the code on vscode and tried it when I told you it wasnt working, my changes are as follows:

ENTRYPOINT ["nginx"]

CMD ["-g", "daemon off;"]

P.S sorry for all the trouble, and thanks for the helping hand.

With those two lines replaced, it should work.

I created a Dockerfile with your content, commented out the COPY and ADD instructions as I don’t have the files, build the image, started a container from the image: it works.

Note: since the logs are written into the container filesystem, docker logs will not show any logs for the nginx process itself. You might want to check the Dockerfile of the official nginx image, to see how they solved it (see lines 107 to 109).

I don’t know it still doesn’t work, my guess is that it is either with the contents of the files I copied and added or since the book I’m learning from used the latest alpine image from a couple years ago then mine might be creating the issue because of updates on the alpine image over the years. Regardless thanks for the help.

If you would like to replicate the whole setup I will leave the contents of default.conf , nginx.conf in here:

nginx.conf:

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  ‘$remote_addr - $remote_user [$time_
local] “$request” ‘
                      ‘$status $body_bytes_sent “$http_referer”
‘
                      ‘”$http_user_agent” “$http_x_forwarded_
for”’;
    access_log  /var/log/nginx/access.log  main;
    sendfile        off;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}

default.conf:

server {
  location / {
      root /usr/share/nginx/html;
  }
}

To install the tar.gz file you can download it from this link: https://raw.githubusercontent.com/PacktPublishing/Mastering-Docker-Fourth-Edition/master/chapter02/dockerfile-example/files/html.tar.gz

Not sure what to say here, but it works for me once I fixed the encoding problems in the nginx.conf:

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        off;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}

Your single and double quotes were wrong. Note: still log output for the container with docker logs

Please make sure you fix encoding problems of code snippets you copy/paste from websites/pdfs/word documents.

When the container doesn’t work even after you tried recommended fixes, please, always share your error message again even if you think that is the same. If you just didn’t notice the difference, we can spend hours on something that does not even exist.