Notion app logo
Struggling to stay organized and effective? Learn to master your time and tasks with the Effectively Notion course!

Create an Ad Hoc Interactive Docker Container

Learn how to create an ad hoc interactive Docker container.

2020-02-20

Often times I find myself wanting to spin up an ephemeral Docker container. This is the structure of the command I'll use:

docker container run --rm --interactive --tty <IMAGE> <COMMAND>

An example if I want to spin up an Alpine Linux container:

docker container run --rm --interactive --tty alpine sh

Running this command will open a new shell inside of my existing terminal window with the ability to interact with the container.

This command can be run more tersely with the shorthand flags for interactive and tty as well:

docker container run --rm -it alpine sh

The composition of the command:

  • container run: Runs a command in a new container
  • --rm: Automatically removes the container when it exits (when I'm done, this is really nice so that Docker doesn't end up with a bunch of dangling Docker processes [you can experiment with removing this flag, running this command a few time and exiting and running docker ps -a to see what that means])
  • -interactive: Keep STDIN open even if not attached
  • -tty: Allocate a pseudo-TTY
Photo of Chase Adams

Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.

Freebies

Vector Arrow Scribbles
banner image for figma vector arrows scribbles

A figma community project of vectorized hand-drawn arrows.

Go To Figma
Vector Line Scribbles
banner for figma vector line scribbles

A figma community project of vectorized hand-drawn lines.

Go To Figma
Vector Shape Scribbles
banner image of figma vector shapes scribbles

A figma community project of vectorized hand-drawn shapes.

Go To Figma

Subscribe to my Newsletter

Every other week I publish the Curiously Crafted newsletter.

In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.

Online

I'm on almost all social media as @curiouslychase.

The curious logo of Chase Adams: glasses and a bow tie.stay curious.