DEV Community

klo2k
klo2k

Posted on

Building Docker image from stdin/pipe

Using - as docker build parameter, you can pipe in any text as your Dockerfile.

I use this trick to quickly test parts of a Dockerfile.

e.g.:

# Build the image, with '-' + heredoc as input
# Works the same with pipe input
docker build --tag klo2k/test - <<'EOT'
FROM ubuntu:latest

# Some complicated looking stuff you wanna try out quickly
RUN <<'EOS' /bin/bash
  echo "${HOSTNAME}" > /tmp/out
EOS

CMD echo "Build: $(cat /tmp/out) Run: ${HOSTNAME}"
EOT

# Run
docker run --rm -it klo2k/test
Enter fullscreen mode Exit fullscreen mode

Example Output:

Build: buildkitsandbox Run: a16cd7dc16ed
Enter fullscreen mode Exit fullscreen mode

Hope you find this useful!

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay