Ostap Lisovyj
Ostap Lisovyj

Reputation: 190

Copy file from local machine to docker

I've created a nodejs application which uses external files to read various configurations and I've created a docker container for this app. I need this app to read the config files (since they will be changed from time to time) from the host machine without rebuilding the whole docker container. How can this be done?

Upvotes: 2

Views: 1547

Answers (1)

michaelbahr
michaelbahr

Reputation: 4973

You should use docker volumes to read those config files from your host.

docker run -v /host/config_files:/container/nodejs/config_files

Your nodejs application can just access the files residing in /container/nodejs/config_files while you can change them on your host.

var config = require('./config_files/some.properties');

I did something similar for a dev project of mine.

My approach was to use an ENTRYPOINT that clones the git repo everytime the container is started and automatically starts the nodejs service.

This is achieved in the Dockerfile with

FROM ...
...
ENTRYPOINT git clone https://github.com/my/repo.git && nodejs someService

Other ideas:

  • mount an external volume and copy the needed files through an ENTRYPOINT command
  • upload your files to a repository like github and use the command shown above
  • create symbolic links within your nodejs file structure that reference files from a docker volume

Upvotes: 3

Related Questions