Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - COPY file from different working directory to another is not working

Tags:

docker

copy

I'm using:

Docker 18.09.1
Ubuntu 16.04

I want to copy a file from a specific folder from my docker image to another folder in my docker image using the Dockerfile.

My docker commands are:

sudo docker build -t mytest .
sudo docker run mytest

My Dockerfile is:

FROM ubuntu:16.04

RUN mkdir -p out/
COPY . out/            <---- this works
COPY /usr/bin/yes /opt <---- this doesn't work!!

CMD out/helloworld

I have a C++ application called helloworld on my out/ working folder. However, I want to copy a file called "yes" which is under /user/bin/ to my /opt folder.

I've tried the COPY command and also the CMD command but without success.

I tried to check if the file was there by running the command on my Ubuntu VM:

docker run mytest ls -l /opt
total 0

My COPY try:

COPY /usr/bin/yes /opt

My CMD try:

CMD ["cp /usr/bin/yes /opt"]

Error:

COPY failed: stat /var/lib/docker/tmp/docker-builder737799611/usr/bin/yes: no such file or directory

Both doesn't work. How can I copy a file to another folder (inside the same docker image)?

like image 404
waas1919 Avatar asked Dec 05 '22 09:12

waas1919


1 Answers

This is stated here that you cannot use absolute path to copy file from your host to your container. It is not supported: https://github.com/moby/moby/issues/4592. So you have to prepare all your files in your current directory first.

like image 152
nivhty Avatar answered Mar 13 '23 05:03

nivhty