---
title: Run your Rust image as a container
linkTitle: Run containers
weight: 10
keywords: rust, run, image, container,
description: Learn how to run your Rust image as a container.
aliases:
- /language/rust/run-containers/
- /guides/language/rust/run-containers/
---
## Prerequisite
You have completed [Build your Rust image](build-images.md) and you have built an image.
## Overview
A container is a normal operating system process except that Docker isolates this process so that it has its own file system, its own networking, and its own isolated process tree separate from the host.
To run an image inside of a container, you use the `docker run` command. The `docker run` command requires one parameter which is the name of the image.
## Run an image
Use `docker run` to run the image you built in [Build your Rust image](build-images.md).
```console
$ docker run docker-rust-image
```
After running this command, you’ll notice that you weren't returned to the command prompt. This is because your application is a server that runs in a loop waiting for incoming requests without returning control back to the OS until you stop the container.
Open a new terminal then make a request to the server using the `curl` command.
```console
$ curl http://localhost:8000
```
You should see output like the following.
```console
curl: (7) Failed to connect to localhost port 8000 after 2236 ms: Couldn't connect to server
```
As you can see, your `curl` command failed. This means you weren't able to connect to the localhost on port 8000. This is normal because your container is running in isolation which includes networking. Stop the container and restart with port 8000 published on your local network.
To stop the container, press ctrl-c. This will return you to the terminal prompt.
You didn't specify a port when running the application in the container and the default is 8000. If you want your previous request going to port 8000 to work, you can map the host's port 3001 to the container's port 8000:
```console
$ docker run --publish 3001:8000 docker-rust-image
```
Now, rerun the curl command. Remember to open a new terminal.
```console
$ curl http://localhost:3001
```
You should see output like the following.
```console
Hello, Docker!
```
Success! You were able to connect to the application running inside of your container on port 8000. Switch back to the terminal where your container is running and stop it.
Press ctrl-c to stop the container.
## Run in detached mode
This is great so far, but your sample application is a web server and you don't have to be connected to the container. Docker can run your container in detached mode or in the background. To do this, you can use the `--detach` or `-d` for short. Docker starts your container the same as before but this time will "detach" from the container and return you to the terminal prompt.
```console
$ docker run -d -p 3001:8000 docker-rust-image
ce02b3179f0f10085db9edfccd731101868f58631bdf918ca490ff6fd223a93b
```
Docker started your container in the background and printed the Container ID on the terminal.
Again, make sure that your container is running properly. Run the curl command again.
```console
$ curl http://localhost:3001
```
You should see output like the following.
```console
Hello, Docker!
```
## List containers
Since you ran your container in the background, how do you know if your container is running or what other containers are running on your machine? Well, to see a list of containers running on your machine, run `docker ps`. This is similar to how you use the ps command in Linux to see a list of processes.
You should see output like the following.
```console
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3074745e412c docker-rust-image "/bin/server" 8 seconds ago Up 7 seconds 0.0.0.0:3001->8000/tcp wonderful_kalam
```
The `docker ps` command provides a bunch of information about your running containers. You can see the container ID, the image running inside the container, the command that was used to start the container, when it was created, the status, ports that were exposed, and the name of the container.