Simple Linux Command Line Using Docker

October 13, 2018

Docker containers are widely used for developing and running anything from web applications to redis caches. However, they can also be useful for running what can effectively be a light VM (a container operates very differently from a VM, but we are just talking about the usecase). I like to use a container for accessing the the Linux command line. However, many users do not know how to run a container in the background and access the shell. Here is a simple way to do so, with a very minimal Ubuntu container:

  • Create a directory and a Dockerfile inside. Use the linked Dockerfule above for a minimal Ubuntu configuration.
  • Build the container with your desired image name: docker build -t <image_name> .
  • Run the container in the background: docker run -t -d <image_name>
  • Identify container name: docker container ls
  • Connect to the Linux shell in the container: docker exec -i -t <container_name> /bin/bash
  • When done, kill the background container process: docker kill <container_name>

Send me a message @HashedDan on Twitter for any questions or comments!