How to Run a Docker Image as a Container?

Better Stack Team
Updated on August 1, 2022

Docker runs processes in isolated containers. A container is a process that runs on a host. The host may be local or remote. When an operator executes docker run, the container process that runs is isolated in that it has its own file system, its own networking, and its own isolated process tree separate from the host.

The specific way to run it depends on whether you gave the image a tag or name.

To see if your docker image has a name, list the images using the docker images command and look for the tag or repository column:

 
docker images
 
Output:
REPOSITORY          TAG                 ID                  CREATED             SIZE
ubuntu              12.04               8dbd9e392a96        4 months ago        131.5 MB (virtual 131.5 MB)

To run a Docker image with a name, use the following syntax:

 
docker run -i -t ubuntu:12.04 /bin/bash

To run a Docker image with the image id, use the following syntax

 
docker run -i -t 8dbd9e392a96 /bin/bash

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github