I am using Docker to write a file on the fly and run it. The command looks like this so far (just to test the idea first):
docker run dockerfile/python cat <<EOF >hi.txt && tail hi.txt
> hi there
> EOF
For some reason this does not echo anything.
If I run this command without a HEREDOC then it does output the result. For example the following works:
docker run dockerfile/python cat > hi.txt && ls
hi.txt
How do I output the result of a multi line run command/HEREDOC.
I'm curious, what shell are you using so that the second command works? Because in bash the
hi.txt
is created on the host and so is thels
.To achieve that, I'd have to use:
IMO, the simplest way to test stuff is to just use a container as a sandbox:
And then just do stuff in that container's shell. Once I got things running well, I backport what I've done in a Dockerfile.
I was fiddling with crossbuild* and was wondering about how to use here documents to pipe commands to a Docker container. Here's the solution.
Quick rundown of what's happening.
--rm
tells Docker to remove the container when it finished execution, otherwise it would show up in the outputdocker ps -a
(not mandatory to use of course)--interactive
,-i
is needed, otherwise/bin/bash
would not run in an interactive environment and would not accept the here document from stdin as its input-s
flag passed to/bin/bash
--volume $(pwd):/workdir
, just-v
will mount the current working directory on the host to/workdir
in the container--env CROSS_TRIPLE=x86_64-apple-darwin
, or simple-e
tells thecrossbuild
container about the target platform and architecture (the container's entry point is/usr/bin/crossbuild
, which is a shell script and based on the environment variable it's symlink the right toolchain components to the right places for the cross compilation to work)multiarch/crossbuild
the name of the Docker container to run (available in Docker Hub)The commands can be fed to Docker like this as well.
Hoped this helps.
Update
Actually it seems you don't even need to use
/bin/bash -s
, it can be ommited, at least for thecrossbuild
container, YMMV.*Linux based container used to produce multi-arch binaries: Linux, Windows and OS X, very cool.