Piping a file into docker run

DockerPipe

Docker Problem Overview


I need to pipe (inject) a file or some data into docker as part of the run command and have it written to a file within the container as part of the startup. Is there best practise way to do this ?

I've tried this.

cat data.txt |  docker run -a stdin -a stdout -i -t ubuntu /bin/bash -c 'cat >/data.txt'

But can't seem to get it to work.

Docker Solutions


Solution 1 - Docker

cat setup.json |  docker run -i  ubuntu /bin/bash -c 'cat'

This worked for me. Remove the -t. Don't need the -a's either.

Solution 2 - Docker

The better solution is to make (mount) you host folder be accessible to docker container. E.g. like this

docker run -v /Users/<path>:/<container path> ... 

Here is /Users/<path> is a folder on your host computer and <container path> mounted path inside container.

Also see Manage data in containers manual page.

UPDATE another Accessing External Files from Docker Containers example.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1513388View Question on Stackoverflow
Solution 1 - DockerjamieView Answer on Stackoverflow
Solution 2 - DockerAndriy KryvtsunView Answer on Stackoverflow