> For the complete documentation index, see [llms.txt](https://docs.arkannis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arkannis.net/containerization/docker/docker-cheatsheet.md).

# Docker Cheatsheet

## Running containers

#### Run container:

```bash
docker run
```

#### Run container in daemon mode:

```bash
docker run -d
```

#### Run container in daemon mode and set name:

```bash
docker run -d --name <name_of_container>
```

## Process

#### Show docker processes:

```bash
docker ps
```

## Images

#### Search of Images:

```bash
docker search <image_name>
```

#### Pull images from repo:

```bash
docker pull <image_name>
```

#### Show local images:

```bash
docker images
```

#### Remove docker images:

```bash
docker rmi <image_name>
```

#### Force remove docker images:

```bash
docker rmi -f <image_name>
```

## Build

#### Build docker container from docker file:

```bash
docker build -t <docker_file>
```

#### Build container but do not start the container:

```bash
docker start <docker_file>
```

## Container interaction

#### Basic command for interaction:

```bash
docker exec
```

#### Connect to interactive shell for a container

```bash
docker -exec -i -t <container_name>

docker -exec -it <container_name>
```

## Network

#### Display docker networks:

```bash
docker network
```

#### Create docker network:

```bash
docker network create <network_name>
```

#### Remove docker network

```bash
docker network rm <network_name>
```

## System

#### Remove all stopped containers, dangling images and unused networks (basically cleanup)

```bash
docker system prune
```

## Secrets

#### Create secrets that can be passed to docker:

```bash
docker secret create <secret_name> <file_name>
```

## Quick Remove

#### Remove all containers from server with one line:

```bash
docker service rm $(docker service ls -q)
```

## Resources

* [Official Docker documentation for all commands](https://docs.docker.com/engine/reference/run/)
