Questions tagged [docker-copy]

26 questions
563
votes
7 answers

COPY with docker but with exclusion

In a Dockerfile, I have COPY . . I want to exclude an entire directory, in my case, node_modules directory. Something like this: COPY [all but **/node_modules/**] . Is this possible with Docker?
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
28
votes
1 answer

Copy entire directory from container to host

I'm trying to copy an entire directory from my docker image to my local machine. The image is a keycloak image, and I'd like to copy the themes folder so I can work on a custom theme. I am running the following command - docker cp…
Harry Blue
  • 4,202
  • 10
  • 39
  • 78
23
votes
1 answer

Docker multistage: how to COPY built files between stages?

I'm beginner with Docker, and I'm trying to build an image in two stages, as explained here: https://docs.docker.com/develop/develop-images/multistage-build/ You can selectively copy artifacts from one stage to another Looking at the examples…
bli
  • 7,549
  • 7
  • 48
  • 94
18
votes
2 answers

docker view directory within container

I'm trying to copy some files from my docker container to my localhost, I read the documentation that the way to do this is docker cp 'container':path/to/file dest/path But this requires I know the path and directory within the container that I…
Meir Snyder
  • 789
  • 1
  • 6
  • 16
13
votes
2 answers

`--chown` option of COPY and ADD doesn't allow variables. There exists a workaround?

In a Dockerfile, the common way to copy a directory as a non-root user (e.g $UID 1000) is the following: COPY --chown=1000:1000 /path/to/host/dir/ /path/to/container/dir However, I want to use variables instead. For example ARG USER_ID=1000 ARG…
gvgramazio
  • 1,115
  • 3
  • 13
  • 30
11
votes
2 answers

Docker-Compose not able to copy haproxy.cfg

My problem is that I have a docker-compose.yml file and an haproxy.cfg file and I want docker-compose to copy the haproxy.cfg file to the docker container. As per the post Docker composer copy files I can use volumes to do it but in my case I'm…
utkarsh31
  • 1,439
  • 2
  • 13
  • 20
5
votes
3 answers

How to copy a directory over the docker cp?

I want to copy a directory from the host to a container, but I couldn't use the following command: $ docker cp -r :/destination/path unknown shorthand flag: 'r' in -r With scp -r shell command I can do it, so I expected the…
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
4
votes
0 answers

Docker ignore file for multistage build

I need to exclude file in Docker COPY for the first stage but use it in another COPY for the second stage, because it breaks docker layer caching. My folder structure looks like: src/ public/ .env package.json nginx.conf My Dockerfile looks like…
Nick Roz
  • 3,918
  • 2
  • 36
  • 57
3
votes
1 answer

Copy directory into docker build no matter if empty or not - fails on "COPY failed: no source files were specified"

I have directory csv in context directory of docker build. I want to copy it into docker image in all circumstances (for empty directory in host an empty directory inside image is created, for nonempty directory in host it is copied with all…
Tomáš Záluský
  • 10,735
  • 2
  • 36
  • 64
3
votes
1 answer

Is it better to COPY multiple project files in separate layers, or in one go when creating a Docker image?

I am creating a Docker container from this .NET Core application that has multiple projects inside the solution, and I wonder if it is better to COPY each project file separately, or in a single line. Visual Studio generates a Dockerfile that copies…
Marthe Veldhuis
  • 316
  • 2
  • 16
2
votes
1 answer

Podman says a directory doesn't exist when it does while copying

I'm getting stuck on a Dockerfile with: [2/2] STEP 31/42: COPY /opt/SIMULATeQCD/src /simulateqcd/src Error: error building at STEP "COPY /opt/SIMULATeQCD/src /simulateqcd/src": checking on sources under "/opt/SIMULATeQCD/podman-build": copier: stat:…
Grant Curell
  • 1,321
  • 2
  • 16
  • 32
2
votes
1 answer

How to cp data from one container to another using kubernetes

Say we have a simple deployment.yml file: apiVersion: apps/v1 kind: Deployment metadata: namespace: ikg-api-demo name: ikg-api-demo spec: selector: matchLabels: app: ikg-api-demo replicas: 3 template: metadata: …
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
2
votes
2 answers

How to copy multiple files in one layer using a Docker file to different locations?

Is it possible to copy multiple files to different locations in a Dockerfile? I'm looking to go from: COPY outputs/output/build/.tools /root/.tools COPY outputs/output/build/configuration /root/configuration COPY…
user3292394
  • 609
  • 2
  • 11
  • 24
1
vote
3 answers

Docker, Copying image, error - ERROR: failed to solve: failed to compute cache key: failed to calculate checksum

i'm doing a tutorial in docker, and trying to copy a image from docker, and reference the index.hmtl file im my local file, vinnyx05 -> is my login at docker, im running docker desktop. in using Windows 11. the code is: PS C:\html> docker build -t…
1
vote
2 answers

dockerfile copy list of files, when list is taken from a local file

I've got a file containing a list of paths that I need to copy by Dockerfile's COPY command on docker build. My use case is such: I've got a python requirements.txt file, when inside I'm calling multiple other requirements files inside the project,…
drizzt13
  • 630
  • 6
  • 15
1
2