Terminus
Start a Docker Container

Start a Docker Container

[#start-a-new-container] The short answer [#start-a-new-container]

To start a Docker container in the foreground of the terminal based on an existing Docker image, you can use the [.inline-code]docker run[.inline-code] command as follows:

$ docker run -it <image> 

Where:

  • The [.inline-code]-i[.inline-code] flag is used to launch the container in interactive mode, allowing it to accept input from the command line.
  • The [.inline-code]-t[.inline-code] flag is used to allocate a terminal within the container, making it behave like a regular terminal interface.

Note that this command will automatically download the image on your local machine from the configured Docker registry if not present.

Also note that you can find the list of images present on your system using the [.inline-code]docker images[.inline-code] command.

For example:

$ docker run -it ubuntu
root@2ce91ff7d776:/#

You can learn more about restarting containers by reading our other article on how to restart stopped containers in Docker.

[#start-a-new-container-in-detached-mode] Starting a container in the background [#start-a-new-container-in-detached-mode]

To start a container in the background (i.e. "detached mode"), you can use the [.inline-code]docker run[.inline-code] command with the [.inline-code]-d[.inline-code] flag as follows:

$ docker run -d < image> 

[#easily-recall-commands-with-ai] Easily retrieve these commands using Warp's AI Command Suggestions feature [#easily-recall-commands-with-ai]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Entering [.inline-code]docker launch container background[.inline-code] in the AI Command Suggestions will prompt a [.inline-code]docker[.inline-code] command that can then quickly be inserted into your shell by doing [.inline-code]CMD+ENTER[.inline-code].