Docker packages software into standardized units called [[Containerization|containers]] that have everything the software needs to run including libraries, system tools, code, and runtime. Because all of the containers share the services of a single [[operating system kernel]], they use fewer resources than [[Virtual Machines|virtual machines]].^[[What is a Container? | Docker](https://www.docker.com/resources/what-container/)]
![[docker-containerized-appliction-blue-border_2.png|350]]![[container-vm-whatcontainer_2.png|350]]
## Docker Compose
https://www.composerize.com/
# Basic Commands
## Container Management
### List Containers
https://docs.docker.com/reference/cli/docker/container/ls/
```
docker ps
```
|Option|Description|
|---|---|
|[`-a, --all`](https://docs.docker.com/reference/cli/docker/container/ls/#all)|Show all containers (default shows just running)|
### Connect to container
```bash
docker exec -t -i mycontainer /bin/bash
```
## Compose Management
### Verify Compose
```bash
docker compose config
```
If the configuration file is spit back at you then you're good to go!
### Start Compose
```
docker-compose up -d
```
### Stop & Remove Containers
```
docker-compose down
```
Stops containers and removes containers, networks, volumes, and images created by `up`.^[https://docs.docker.com/reference/cli/docker/compose/down/]
### Restart Single Container
```bash
docker compose restart container
```
### Reset Environment
```bash
docker system prune -a --volumes --force
```
# Installation
## Ubuntu - APT Repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
[Docker Ubuntu Installation Guide](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)
1. Set up Docker's `apt` repository.
```bash
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
```
2. Install the Docker packages.
```bash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```
## Post Installation
## Add user to docker group for non-root management
If you don't want to preface the `docker` command with `sudo`, create a Unix group called `docker` and add users to it.^[[Linux Post-installation steps | Docker Docs](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user)]
1. Create the `docker` group
```bash
sudo groupadd docker
```
2. Add your user to the `docker` group.
```bash
sudo usermod -aG docker $USER
```
3. Activate the group changes
```bash
newgrp docker
```