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.
Related
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.
I'm kind of new to Docker, and I'm running into an issue I can't find a straightforward explanation for. I have a pretty simple Dockerfile that I'm building into an image, but when I deploy the image to Kubernetes as a pod, the results aren't what I expect.
FROM ubuntu:16.04
RUN mkdir workspace
WORKDIR /workspace
COPY . /workspace
CMD ["ls"]
When I check the logs for the deployment, there are no files listed in the /workspace folder, even though the folder itself exists. However, if I change my COPY's destination to a default linux folder like /usr, the files are there as I'd expect. My suspicion is that this has something to do with storage persistence, but since I'm copying the files into the folder when I build my image and the folder persists in the pod, I'm at a loss for why this happens. Any guidance would be greatly appreciated.
I would venture to guess that the ubuntu:... image doesn't have a WORKDIR set to /, and hence your copy command isn't working as expected.
Try changing the run command to be RUN mkdir /workspace and I think you'll see what you expected.
Hope this helps.
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 have the following in my Dockerfile - I'm trying to copy all the contents of the source folder (a folder of JARs) to the destination but it simply doesn't work.
Any ideas?
RUN cp -R /tmp/usr/kafka-connect/. /etc/kafka-connect/jars/
I've also tried
RUN cp -R /tmp/usr/kafka-connect/ /etc/kafka-connect/jars/
and
RUN cp -a /tmp/usr/kafka-connect/. /etc/kafka-connect/jars/
with no luck.
What am I doing wrong?
Thanks.
You need to use COPY instead of RUN.
COPY /tmp/usr/kafka-connect /etc/kafka-connect/jars
You can also use the WORKDIR instruction and then the destination path can be relative to WORKDIR.
The source path can be relative to the build context.
I have a simple Dockerfile:
FROM php:7.1-apache
LABEL maintainer="rburton#agsource.com"
COPY C:/Users/rburton/code/MyAgsourceAPI /var/www
It is the last line that is giving me problems. I am copying from a Windows structure to a docker container (Linux I assume). When I build this image I get:
...
Step 3/3 : COPY C:/Users/rburton/code/MyAgsourceAPI /var/www
COPY failed: stat /var/lib/docker/tmp/dockerbuilder720374851/C:/Users/rburton/code/MyAgsourceAPI: no such file or directory
First, something is preventing the recognition that this is an absolute path and naturally if the path is pre-pended with /var/lib/docker/tmp/dockerbuilder720374851 then the file will not be found. Second, I have tried / and \ but all with the same result. Also the drive letter I suspect is confusing to docker. So the question is how do I copy files and folders (along with the contents) from a Windows folder to a docker container?
First, change your Dockerfile to:
FROM php:7.1-apache
LABEL maintainer="rburton#agsource.com"
COPY MyAgsourceAPI /var/www
Then, to go your code directory: cd Users/rburton/code.
Within that directory, run:
docker build -t <image_name> .
Another tip that might be helpful, I've seen same issue while running build from correct context, and issue remained until I've used all small caps on src folder that I wanted to copy from. eg:
COPY MyAgsourceAPI /var/www -> COPY myagsourceapi /var/www
The root of the path is relative to the Dockerfile and not your Windows filesystem.
If for example your filesystem is layed out like this:
+-+-MyProject
|
+---Dockerfile
|
+-+-build
|
+---MyAgsourceAPI
You can use:
COPY /build/MyAgsourceAPI /var/www
Note that "MyProject" (or anything above it) is excluded from the path.