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:
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:
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:
[#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:
![](https://cdn.prod.website-files.com/64b7506ad75bbfcf43a51e90/66904b1173a082e29d703876_AD_4nXc__yAcPBZ07h16ieYOhhFnyQ4o5ru2dOmZVuDbH2KKQmCjU6UFoGEkgiC-NLRx4j8_wPCkfyMtG79h1IWnUAUPNIiSwg_2bcB_UqlItjYPcjBtjyoE1qMF9pX_EntKYniO5TYTTyCk1IY73xr927HlkJx3.gif)
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].