# Manipulating containers

## Manipulating containers&#x20;

### List containers

Since we ran our container in the background, how do we know if our container is running or what other containers are running on our machine? Well, we can run the `docker ps` command. Just like on Linux to see a list of processes on your machine, we would run the `ps` command. In the same spirit, we can run the `docker ps` command which displays a list of containers running on our machine

### List running containers

```
docker ps
```

<figure><img src="/files/2pxihaEF9r6jzGbWpq5n" alt=""><figcaption></figcaption></figure>

### Stop running container

```
docker stop romantic_taussig
```

<figure><img src="/files/d45HxKWjYbhHVdySnjJy" alt=""><figcaption></figcaption></figure>

### Restart a container&#x20;

```
docker restart romantic_taussig
```

<figure><img src="/files/ZPkrzBUV7uhHhK2D4sqo" alt=""><figcaption></figcaption></figure>

#### Why did we restart instead of using start?

Notice that the container we just restarted has been started in detached mode and has port 80 exposed. Also, observe the status of the container is `Up X seconds`. **When you restart a container, it starts with the same flags** or commands that it was originally started with.

### What if we do not want random names?

Standard practice is to name your containers for the simple reason that it is easier to identify what is running in the container and what application or service it is associated with.

To name a container, we just need to pass the `--name` flag to the `docker run` command.

```docker
docker run -d -p 5000:80 --name dotnet-app dotnet-docker
```

That’s better! We can now easily identify our container based on the name we want and not any random name.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://raviram.gitbook.io/docker/build-an-image/web-app-experiment/manipulating-containers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
