Skip to content

Instantly share code, notes, and snippets.

@audionerd
Last active August 29, 2015 13:56
Show Gist options
  • Save audionerd/8962594 to your computer and use it in GitHub Desktop.
Save audionerd/8962594 to your computer and use it in GitHub Desktop.
Upload a file from a host filesystem to a running Docker container

Upload a file from a host filesystem to a running Docker container

The best way to do this is probably via docker volumes. For dokku, check out dokku-persistent-storage

But here's a quick hack using netcat anyway.

Assuming we've found the container ID (e.g.: via docker ps):

$ CID=f7a29d6dc8e4

Get the IP address of the container:

$ CIP=`docker inspect -format '{{ .NetworkSettings.IPAddress }}' ${CID}`

Specific the local path and destination path:

$ LN=db/seeds/local.file.txt
$ DN=db/seeds/remote.file.txt

In the docker container, netcat listens:

$ echo "nc -l 1234 > $DN" | docker attach $CID

Meanwhile, on the host, netcat sends:

$ nc $CIP 1234 < $LN

You won't see any output of docker attach. But, if you're already attached in another window, you can monitor the progress. Or, while you run the commands, you could probably tail a log of the container with docker logs -f $CID.

REFERENCES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment