Skip to content

Testing a command inside a docker container (or getting an interactive session)

I’ve used Docker but know very few commands (my favorite command being “docker prune”, to clean up images on a machine). Here’s one I run into so I’m writing it down.

I had an image and I needed to verify what version of yarn was running in it.


docker run -it <image name>

Drops me into an interactive shell for that image. From there, I can run yarn version to see what’s up.

I would often get this advice:

docker exec <container name>

However, note that that’s for a container, not an image. It can be run on a running container. You can find those out by running docker ps or docker container list or docker container ls.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.