Is there a better way to copy files and folders to a docker container?

Viewed 94

This is what I came up with but it seems clunky to me. Is there a way to streamline the COPY command? Note that not all the folders need to copied.

I did check out Docker's documentation regarding, and it seems like this may be the only way? I was just checking if anyone else had a brighter idea. Thanks!

# Copy files to container
COPY src/ /opt/build_area/src/
COPY public/  /opt/build_area/public/
COPY app.js doc* .en* tag-push.sh react-0.3.1.tgz package.json .npmrc /opt/build_area/

This is the folder structure:

$ tree -L 1
.
├── .dockerignore
├── .env
├── .env.development
├── .git/
├── .gitignore
├── .npmrc
├── Dockerfile
├── Dockerfile-build
├── README.md
├── app.js
├── azure-pipelines-static.yml
├── azure-pipelines.yml
├── docker/
├── docker-compose-run.yml
├── docker-compose.yml
├── node_modules/
├── package-lock.json
├── package.json
├── public/
├── react-0.3.1.tgz
├── src/
├── tag-push.sh
└── test-azure-pipelines-static.yml

5 directories, 18 files
2 Answers

This is what I came up with helpful comments from @TahaNaqvi and @DavidMaze. This is much easier to read.

# Copy files to container
WORKDIR /opt/build_area/

COPY src/ ./src/
COPY public/  ./public/

COPY app.js           \
     .npmrc           \
     doc* .en*        \
     tag-push.sh      \
     package.json     \
     react-0.3.1.tgz  /opt/build_area/
Related