List of Docker Container Commands you should know - Docker tips and tricks
Tags: webdev, docker, showdev, devops
Published: 2020-11-11 14:18:55


# List of Docker Container Commands you should know - Docker tips and tricks

This article covers list of commands that you should know to manage docker containers in your local machine or server. some of the important commands are docker list containers, start a container and stop container from docker.

## What is Docker Container

Docker container is an isolated packages of software that you can use to run your application, code or any infrastructure. basically, it helps to manage your application code without conflicting with your current machine/server setup.

## Commands

There are few commands that you need to know to manage docker container. let's start with basic commands.

### Start/Stop Container

To start/stop a docker container, you can do that using the command,

```bash
docker container start [OPTIONS] <Container id>
```

> Note: you can specify the name or you can just specify the first two digits of the container id.

![docker container commands](https://dev-to-uploads.s3.amazonaws.com/i/lzpfsiqotyek3ed4ot2j.png)

## docker stop container

To stop the container, you need to specify the `stop` in the docker container command.

```bash
docker container stop [OPTIONS] <Container id>
```

![docker container commands](https://dev-to-uploads.s3.amazonaws.com/i/2atr8aqpe7jz6u3c6svo.png)

## docker stop all container

To stop all the running container, you can use the command,

```bash
docker stop $(docker ps -a -q)
```

## Remove all stopped containers

Once you stop all containers, you can remove it using the command,

```bash
docker container prune
```

![docker containers list](https://dev-to-uploads.s3.amazonaws.com/i/5gjldpsrua034vic649z.png)

## Docker list containers

To list all the docker container, you can do that using the command,

```bash
docker container ls [OPTIONS]
```

you can add options such as

1. `--all or -a` it shows all the containers in the docker
2. `--size or -s` , displays the container along with size
3. `--latest or -l` shows latest container first
4. `--last or -n` it shows the lastly created containers

![docker container commands](https://dev-to-uploads.s3.amazonaws.com/i/9hsv7bsa8q5lw5lax3x3.png)

![docker containers](https://dev-to-uploads.s3.amazonaws.com/i/z53dyue3qoswu2ki1zlk.png)

## Kill Container

To kill a docker container, you can use the command

```bash
docker container kill [OPTIONS] <Container ID>
```

there is a difference between `docker stop` and `docker kill` container commands. `docker stop` will send a signal `SIGTERM` and then after some grace period it sends the signal `SIGKILL` to stop the containers whereas in `docker kill` command, it sends the `SIGKILL` command directly.

you need to be careful with `docker kill` command, my personal suggestion would be to use `docker stop` command. to explain it a simple way, difference is like shutting down your computer vs forcefully removing the plug from socket to turn off the machine.

## Conclusion

So far, we have seen the important command that you need to know for docker containers. try to use the above commands and play with it to get hands-on experience. if you feel like any important commands are missing, let me know in the comments below. Happy Coding 🙂

Checkout more blog like this here https://cloudnweb.dev/