I cannot copy file to container from my host.
this is my docker file :
COPY /vagrant/somefile.json somefile.json
This is the full path to the file :
/vagrant/somefile.json
this is the path of the Dockerfile:
/vagrant/static/app/Dockerfile
i get :
---> dba663c523a9
Step 3/20 : COPY /vagrant/somefile.json somefile.json
ERROR: Service 'node' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder330278780/vagrant/somfile.json: no such file or directory
To quote the COPY documentation:
The path must be inside the context of the build
In layman's words, any file you want to copy in to the container needs to be in the same directory as the Dockerfile, or some subdirectory of it. If you start by placing somefile.json in /vagrant/static/app/, you should be able to use:
COPY ./somefile.json somefile.json
Generic Format:
copy_command source_file Destination
Please try this!
COPY /vagrant/somefile.json /root/somefile.json
OR
COPY /vagrant/somefile.json /tmp/somefile.json
OR
mkdir ~/new
COPY /vagrant/somefile.json ~/new/somefile.json
Related
I have a dockerfile
FROM myregistry.de/public/12/s11
LABEL maintainer="Me"
COPY ./somefile.txt /opt
CMD /bin/sh
the file I want to copy to Docker Container is in the same folder as the Dockerfile
But when I do docker build -t 'name:tag4' .
I get the error message :
COPY failed: file not found in build context or excluded by .dockerignore: stat somefile.txt: **file does not exist**
So why is this simple copy not working ?
Please check what you get in build context directory by creating another Dockerfile with the following content:
FROM myregistry.de/public/12/s11
RUN mkdir /tmp/build
COPY . /tmp/build
CMD /bin/sh
Then build and run the container and check /tmp/build folder contents.
I want to get the data from the variable Build.Repository.LocalPath and use it in my Dockerfile, but it shows me and error.
This is my dockerfile:
FROM microsoft/aspnet:latest
COPY "/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
I get this error:
Step 2/9 : COPY "/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
failed to process "\"/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/\"": missing ':' in substitution
##[error]C:\Program Files\Docker\docker.exe failed with return code: 1
I have try a lot of ways, putting this line:
COPY "/${Build.Repository.LocalPath}/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
You can add in the Dockerfile an argument:
ARG path
In the Azure DevOps Docker task add an argument:
-task: Docker#2
inputs:
command: build
arguments: --build-arg path=$(Build.Repository.LocalPath)
Now the Dockerfile know the variable value and you can use it, for example:
FROM ubuntu:latest
ARG path
ECHO $path
Results:
Step 3/13 : RUN echo $path
---> Running in 213dsa3dacv
/home/vsts/work/1/s
But if you will try to copy the appliaction in this way:
FROM microsoft/aspnet:latest
ARG path
COPY $path/README.md /inetpub/wwwroot
You will get an error:
COPY faild: CreateFile \?\C:\ProgramData\docker\tmp\docker-builder437597591\_work\1\s\README.md: The system cannot find the path specified.
It's because the Docker build the image within a temporary folder and he copy the sources to there, but he doesn't copy the agent folders (_work/1/s) so the best way it's just put a relative path where the Dockerfile exist, for example (if the Dockerfile exist with the README.md):
FROM microsoft/aspnet:latest
COPY README.md /inetpub/wwwroot
build variables are not available in the dockerfile, but that doesnt matter, as if you put the docker file in the repo root, you can use relative path, so this would work:
COPY "/NH.Services.WebApi/bin/Release/Publish/" /inetpub/wwwroot
I have the docker file as follows:
FROM node:8 as builder
WORKDIR /usr/src/app
COPY ./src/register_form/package*.json .
RUN npm install
COPY ./src/register_form .
RUN yarn build
FROM tensorflow/tensorflow:1.10.0-gpu-py3
COPY --from=builder /usr/src/app/register_form/build/index.html /app/src/
WORKDIR /app
ENTRYPOINT ["python3"]
CMD ["/app/src/main.pyc"]
However, it cannot copy the index.html from the builder stage. Although when I list the folder in the first stage, the files are there.
The error is:
Step 8/22 : COPY --from=builder ./register_form/build/ /app/src/
COPY failed: stat /var/lib/docker/overlay2/5470e05501898502b3aa437639f975ca3e4bfb5a1e897281e62e07ab89866304/merged/register_form/build: no such file or directory
How can I fix this problem - the COPY --from=builder docker command?
I think you are misusing COPY command. As it is told in docs:
If src is a directory, the entire contents of the directory are
copied, including filesystem metadata.
Note: The directory itself is not copied, just its contents.
So your command COPY ./src/register_form . does NOT create register_form folder in container, but instead copies all contents. You can try adding:
RUN ls .
to your Dockerfile to make sure.
As noticed by #BMitch in comments, you can explicitly set destination folder name to achieve expected results:
COPY ./src/register_form/ register_form/
I have the following dockerfile snippet:
RUN mkdir sys_libs
COPY sys_lib/vs_log.rb sys_libs/vs_log.rb
The file does exist in the local ./sys_lib folder.
when I attempt to build: get:
COPY failed: stat /var/lib/docker/tmp/docker-builder085599896/sys_lib/vs_log.rb: no such file or directory
Note the folder name referenced in the docker path is the name of the local folder, not the name of the docker folder just created.
I get the same if I do a COPY sys_lib/ sys_libs/
If I make the local and the docker folder the same I get the same thing:
RUN mkdir sys_lib
COPY sys_lib/ sys_lib/
I have tried it with leading./ and without on both sides.
I am out of options. Any ideas?
I have a source code and I want to add it into docker image using Dockerfile. I use COPY command, but I don't know what I should put in destination place. Can you tell me if destination is a specific directory or it is optional?
The destination directory can be a directory of your choice.
...
RUN mkdir -p /usr/src/app
COPY ./src /usr/src/app
...
The above commands in a Dockerfile would create /usr/src/app in the containers filesystem and the COPY would copy the contents of the src directory on the host to /usr/src/app in the containers filesystem.
You can use any destination path , but make sure that path exist for example
COPY source_code / opt/folder_name
Then optionally you can make this in docker as working directory
WORKDIR /opt/folder_name
in Dockerfile:
COPY ./src /dst
Where src is a folder in the same path of Dockerfile on the host (the computer on which Docker is directly running). dst is a folder on the container itself.
Here is an example:
Create a Dockerfile for an ASP.NET Core application
# Copy everything
COPY . /FolderInTheContainer/
this will copy everything in the same path of Dockerfile, to a destination folder in the container.
Here is dockerfile copy documentation:
https://docs.docker.com/engine/reference/builder/#copy