Yifeng
Yifeng

Reputation: 11

How to copy a folder to another folder within docker container?

I'm using nginx:alpine docker image.

I try to do the compilation process in Dockerfile, and it generates a folder named dist in the docker container.

At the last step, I try to copy the generated dist folder to /usr/share/nginx/html as instructed in https://hub.docker.com/_/nginx/

What I have tried is:

# Copy dist folder to destination
RUN cp -rf dist /usr/share/nginx/html/

But the result is that when I run the image, the nginx displays the default nginx page.

I have also tried to compile before I run docker build, and at the last step of Dockerfile:

COPY dist /user/share/nginx/html

And this time it works.

Any idea how I can do the compilation in Dockerfile while I can successfully copy the generated dist folder to destination?

Upvotes: 1

Views: 3266

Answers (1)

VonC
VonC

Reputation: 1324148

Maybe try to use two nginx:alpine images (in the same Dockerfile):

  • one for the compilation, where you would generate the dist
  • one where you copy the dist from the first image to your actual final image.

This is described as a multi-stage build.

Upvotes: 1

Related Questions