Docker Community Forums

Share and learn in the Docker community.

How to get files into container

I have a container, but cant figure out how to get files into it. COPY works, but only with the static paths.

Say me and my buddy are both working on the same container, and need the project files added to it.
For me, I can copy from “/home/judah/project/whatever.” For my buddy though, its “/home/judahs-coworker/wherever/he/put/it”. Do we just need to add both locations to the Dockerfile, and have one fail and the other work?

All files must be in the root-folder or within a sub-dir of it. The root-folder is where your “Dockerfile” resides.
You can’t add files from another location.
Let’s say … your root is /home/judah/project/. You can only add files from this or a sub-dir of this folder. But you can’t add files from /home/judahs-coworker/wherever/he/put/it …
So you guys need to agree on a folder-structure where you put your stuff.

Hmm. We are trying to keep stuff separate. We dont really want our infrastructure code in the same repo as our app code.

Thats ok though. Thinking it over, Docker does not seem to be for us since it really limits how well we can work together on the project. Maybe for smaller companies with fewer devs it would work better.

Well you “could” write a script that copy all relevant files in a distictive folder structure so they can be included in your Dockerfile. But more common is to let (e.g.) Jenkins do that work for you.

And yes, the whole container thing is quite a strategy questions. It doesn’t fit all designes/architectures …
It is ment for small “agile” pieces of software that can get frequently changed, modified or updated. Containers work really well when you can break down your whole application in small services or micro-services that can swiftly swaped in and out. But it is a pain when you try pack a big (rather) monolythic application into a docker box.

The normal approach is to put your files under version control (git) and use a - commit triggered - cicd pipeline build the images based on the content of the repository and push the build image to a private image registry.