Ethan
Ethan

Reputation: 5

Docker doesn't COPY files to created directories

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.

Upvotes: 0

Views: 225

Answers (1)

cewood
cewood

Reputation: 1052

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.

Upvotes: 1

Related Questions