2

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
bennettnw2
  • 131
  • 2
  • 5
  • 2
    check this possible duplicate: https://stackoverflow.com/questions/30256386/how-to-copy-multiple-files-in-one-layer-using-a-dockerfile – Taha Naqvi Jan 11 '22 at 15:11
  • 1
    The other shortcut I'd use here is to set `WORKDIR /opt/build_area`, and then `COPY src/ ./src/`, `COPY files ./` relative to that `WORKDIR` to avoid repeating the directory name. – David Maze Jan 11 '22 at 15:17
  • @TahaNaqvi, That is a great post which helps. Thank you! – bennettnw2 Jan 11 '22 at 16:07
  • @DavidMaze, that is a great idea! Thanks for the pointer. – bennettnw2 Jan 11 '22 at 16:08
  • Does this answer your question? [How to copy multiple files in one layer using a Dockerfile?](https://stackoverflow.com/questions/30256386/how-to-copy-multiple-files-in-one-layer-using-a-dockerfile) – Taha Naqvi Jan 12 '22 at 12:50

2 Answers2

1

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/
bennettnw2
  • 131
  • 2
  • 5
1

dockerignore file can be used just like gitignore file. You can specify files folders to be ignored which will not be copied by COPY command. More doc here - https://docs.docker.com/engine/reference/builder/#dockerignore-file

Santosh Karanam
  • 1,077
  • 11
  • 23