# Docker and Podman
## Docker
### Installation
Debian:
```bash
apt-get install docker-engine
```
Red Hat:
```bash
dnf install docker-engine
```
### Images
Pull image
```bash
docker pull <namespace>/<name>:<tag>
```
:::info
:bulb: If no tag is specified, docker will pull the latest version of the image. That is: `docker pull ubuntu`is equivalent to `docker pull ubuntu:latest`
:::
List images
```bash
docker images
```
Inspect docker image
```bash
docker inspect <image>
```
Remove Images
```bash
docker rmi <image>
```
Save Images
```bash
docker save -o <tarfile> <image>
```
Load Images
```bash
docker load -i <tarfile>
```
### Containers
Run a container from image
```bash
docker run -it [-d] [--name <name>] <image> [<command>]
```
Start a stopped container
```bash
docker start <container>
```
Stop a container
```bash
docker stop [-t] <container>
```
Pause a container
```bash
docker pause <container>
```
Unpause a container
```bash
docker unpause <container>
```
List Running Containers
```bash
docker ps
```
List All Containers
```bash
docker ps -a
```
List Recent Container
```bash
docker ps -l
docker ps -n <number>
```
List Containers Using filters
```bash
docker ps -f <key=vlaue>
docker ps -f "name=nginx"
```
View output
```bash
docker logs <container> [--tail <n>] [--since <timestamp>] [-f]
```
Attach and enter a daemon container
```bash
docker attach <container>
```
Execute command in a container
```bash
docker exec [-d] <container> <command>
```
Send signal
```bash
docker kill [-s <signal>] <container>
```
Commit a container's file changes into a new image
```bash
docker commit -m <"message"> <container> <image>
```
Export a container
```bash
docker export -o <tarfile> <container>
```
## Data Volume
### Concepts
* Preferred mechanism for **persistent data storage** Docker containers.
* Volumes can be more shared among multiple containers.
* The contents of a volume exists outside of the lifecycle of a container.

### Command
We can mount the data volume to a container by adding `-v <data volume name>:<destination>` / `-v <source directory>:<destination>` or ` --mount source=<volume>,target=<destination>`.
:::info
when using `docker service`, `-v` is not supported. We can only use `--mount`.
:::
Alternatively, we can manually create a data volume using the following command:
```bash
docker volume create [--name <data volume name>]
```
List all volumes:
```bash
docker volume ls
```
Inspect some basic properties of a volume.
```bash
docker volume inspect <volume>
```
Remove a volume
```bash
docker volume rm <volume>
```
Remove container along with volume
```bash
docker rm -v <volume>
```
:::info
Named volume will not be deleted using `-v` command.
:::
Read only volumes
Add `-v <volume>:<destination>:ro` or `--mount source=<volume>,destination=<destination>,readonly`
### Data container
Example:
Create a data container
```bash
docker create --name data -v /data ubuntu
```
Connect container to data container
```bash
docker run --name container1 --volumes-from data nginx
```
## Docker Networking
### Network drivers
1. **bridge**: The default driver. Usually used when containers need to communicate with other containers <u>running on the same docker host</u>.
## Dockerfile