Reputation: 7028
I am trying to build a docker image, I have dockerfile with all necessary commands. but in my build steps I need to copy one dir from remote host to docker image. But if I put scp command into dockerfile, i'll have to provide password also into dockerfile, which I dont have to.
Anyone has some better solution to do this. any suggestion would be appreciated.
Upvotes: 3
Views: 4416
Reputation: 350
You can copy a directory into a (even running) container at post build time
On remote machine: Copy from remote host to docker host with
scp -r /your/dir/ <user-at-docker-host>@<docker-host>:/some/remote/directory
On docker machine: Copy from docker host into docker container
docker cp /some/remote/directory <container-name>:/some/dir/within/docker/
Of course you can do step 1 also from your docker machine if you prefere that by simply adapting the source and target of the scp command.
Upvotes: 1
Reputation: 3002
I'd say there are at least options for dealing with that:
Option 1:
If you can execute scp
before running docker build
this may turn out to be the easiest option:
scp -r somewhere:remote_dir ./local_dir
COPY ./local_dir some_path
to your Dockerfiledocker build
Option 2: If you have to execute scp
during the build:
RUN
command (to avoid leaving secrets inside the image):
~/.ssh/id_rsa
or start an ssh-agent
and add it;scp
The second option is a bit convoluted, so it may be worth creating a wrapper script that retrieves the required secrets, runs any command, and removes the secrets.
Upvotes: 3