I have a problem where docker build can't find my files and I've tried many folder references but I cant get my head around the folder structure. No matter what its wrong.
This is my project (slimmed down) structure:
This is my docker file:
# pull official base image
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
# set working directory
WORKDIR /app
# add app csprojfiles
COPY ./myapi.sln .
and this is the error:
failed to compute cache key: "/myapi.sln" not found: not found
I've tried COPY ../myapi.sln . and simply myapi.sln but its not found no matter what. Im running command docker build web.api/ from the parent myapi folder in command prompt.
Your path is wrong. By writing COPY ./myapi.sln . you assume that myapi.sln is in the same folder than the Dockerfile which is not the case.
Best practice is to put the Dockerfile at the root of your project so you can easily access all your files.
In anyway, you can't access a parent directory with absolute or relative path.
From the documentation:
The path must be inside the context of the build; you cannot COPY ../something/something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.
Related
There is a directory inside the stain/jena-fuseki:4.0.0 image that cannot be copied while other directories can be. I have the following Dockerfile
FROM python:3.8.15-slim
COPY --from=stain/jena-fuseki:4.0.0 /fuseki /fuseki
If I run docker image build . I get the following response
Sending build context to Docker daemon 435.9MB
Step 1/2 : FROM python:3.8.15-slim
---> f0fe0cb74bac
Step 2/2 : COPY --from=stain/jena-fuseki:4.0.0 /fuseki /fuseki
COPY failed: stat fuseki: file does not exist
However, I looked into the image with docker run -it stain/jena-fuseki:4.0.0 and the directory does exist at the root level along with other directories which are copyable. E.g. following Dockerfile builds perfectly without any errors.
FROM python:3.8.15-slim
COPY --from=stain/jena-fuseki:4.0.0 /jena-fuseki /jena-fuseki
I have tried many things like changing the working directory with WORKDIR / and also things like COPY --from=stain/jena-fuseki:4.0.0 /fuseki/. /fuseki. However, none of them are working.
I have also not excluded anything with .dockerignore
fuseki is a run time directory. It is created when the container is instantiated. So, it is not present at the build time. Hence the error.
This is proved by the timestamp of the files in the screenshot below.
You need to use a multi-stage build, see here: https://docs.docker.com/build/building/multi-stage/#name-your-build-stages
In your case, that would like something like:
FROM stain/jena-fuseki:4.0.0 AS jena
FROM python:3.8.15-slim
COPY --from=jena /jena-fuseki /jena-fuseki
I am using COPY command in my docker file on top of ubuntu 16.04. I am getting error as no such file or directory eventhough the directory is present. In the below docker file I want to copy the directory "auth" present inside workspace directory to the docker image (at path /home/ubuntu) and then build the image.
FROM ubuntu:16.04
RUN apt-get update
COPY /home/ubuntu/authentication/workspace /home/ubuntu
WORKDIR /home/ubuntu/auth
a Dockerfile COPY command can only refer to files under the context - the current location of the Dockerfile, aka .
so you have a few options now:
if it is possible to copy the /home/ubuntu/authentication/workspace/ directory content to somewhere inside your project before the build (so now it will be included in your Dockerfile context and you can access it via COPY ./path/to/content /home/ubuntu) it can be great. but sometimes you dont want it.
instead of copying the directory, bind it to your container via a volume:
when you run the container, add a -v option:
docker run [....] -v /home/ubuntu/authentication/workspace:/home/ubuntu [...]
mind that a volume is designed so any change you made inside the container dir(/home/ubuntu) will affect the bound directory on your host side (/home/ubuntu/authentication/workspace) and vice versa.
i found a something over here: this guy is forcing the Dockerfile to accept his context- he is sitting inside the /home/ubuntu/authentication/workspace/ directory, and running there
docker build . -f /path/to/Dockerfile
so now inside his Dockerfile he can refer to /home/ubuntu/authentication/workspace as his context (.)
I have a folder : /docker on my project root and it contains certain files like Apache configs which I need to copy to the correct folders during teh build.
Project-root
------docker folder
-----------apache.conf
Now
DOCKERFILE
In my dockerfile i have a copy command which copies the whole of root to the container.
`Issue`
I don't want the docker folder to be copied to the built image.
I added docker to the .dockerignore. But this leads to the problem that these files are not sent to the build context and then the build command fails.
WORKAROUND
Use the RUN command in the dockerfile to remove the docker folder instead of using .dockerignore
QUESTION
Is there any better solution?
DOCKER FILe:
FROM <baseimage>
WORKDIR /var/www/html/
COPY . /var/www/html/MYFOLDER
COPY ./docker/apache.conf /etc/httpd/conf/apache.conf
COPY ./docker/sites-enabled /etc/httpd/sites-enabled
So, I am new to Docker but after trying a couple of times I can't get this to work.
Basically I have a simple script like this:
Dockerfile
from centos:7
.....
COPY /C:/Users/Kalin/Drive/web/sites/foo.com/ /var/www
EXPOSE 80
Whenever I run docker build everything works as planned except at the COPY part I get this error:
Step 10/11 : COPY /C:/Users/Kalin/Drive/web/sites/foo.com/ /var/www
COPY failed: stat /var/lib/docker/tmp/docker-builder646917435/C:/Users/Kalin/Drive/web/Kalin/foo.com: no such file or directory
I get the error is about not finding a directory, but instead of looking for it starting from C:/.. foldedr it is looking from /var/...
I don't know what mistake I am doing
I would strongly suggest to make relative path in COPY command so if you have your docker file in /C:/Users/Kalin and you are running docker build from that folder, just place Drive/web/sites/foo.com/ in COPY command
I try to copy my build folder to /usr/share/nginx/html
So I want to have as result:
/usr/share/nginx/html/build/xxx
I perform this inside my dockerfile
cp -r build /usr/share/nginx/html/
But then than all the content of my build/ folder is copied inside /usr/share/nginx/html and not the folder itself
So like: /usr/share/nginx/html/xxx
When I perform the exactly same command inside my running container it happens in the right way!?
Than I got /usr/share/nginx/html/build/xxx
Can someone tell me what I'm doing wrong?
I don't know how exactly the Docker daemon works during image building but according to the documentation for COPY there is a clause that says;
COPY
If is a directory, the entire contents of the directory are
copied, including filesystem metadata. Note: The directory itself is
not copied, just its contents.
Obviously we are talking about the Linux cp command and not docker's COPY but it sounds like the rule somehow seems to have been applied to cp as well?
See:
https://docs.docker.com/engine/reference/builder/#/copy
For fixing your problem - probably just use the ADD command to copy your build directory?
Example: (Assuming your build directory is at the same level as Dockerfile;
ADD build /usr/share/nginx/html/
Let me know if this works for you.