# Docker
Reference docs: https://docs.docker.com/reference/
I should learn more about Docker...
- Integral to how [[Umbrel]] did their magic
- Installation method for [[lnd]]
## Getting started
Download Docker desktop:
https://www.docker.com/get-started
### Tutorial
```shell
# Clone
docker run --name repo alpine/git clone https://github.com/docker/getting-started.git
docker cp repo:/git/getting-started/ .
cd getting-started/
# Build
docker build -t docker101tutorial .
# Run
docker run -d -p 80:80 --name docker-tutorial docker101tutorial
# Save and share
docker tag docker101tutorial {userName}/docker101tutorial
docker push {userName}/docker101tutorial
```
### [Install on Ubuntu](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository)
Link: [[Ubuntu]]
```bash
# Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg lsb-release
# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Use the following command to set up the `stable` repository. To add the nightly or test repository, add the word `nightly` or `test` (or both) after the word stable in the commands below. Learn about nightly and test channels.
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install the latest version of Docker Engine and containerd
sudo apt-get install docker-ce docker-ce-cli containerd.io
# Verify that Docker Engine is installed correctly by running the `hello-world` image
sudo docker run hello-world
```
## Commands
### docker build
Creates an **image** (NOT a container for that image) using a Dockerfile in the current directory
```shell
docker build -t <imagename> .
```
### docker create
Creates a container based on a specified image
```shell
docker create --name <containername> <image>
```
### docker exec -it
Opens a shell into a container
```shell
docker exec -it
```
### docker run
Creates a container AND starts it
https://docs.docker.com/engine/reference/commandline/run/
### docker ps
### To get a shell in the container
1. Use `docker ps` to get the name of the existing container (or reference in GUI)
2. Use the command `docker exec -it <container name> /bin/bash` to get a bash shell in the container.
3. Generically, use `docker exec -it <container name> <command>` to execute whatever command you specify in the container.
### cp
- Use `tldr`
- Make sure to specify absolute path in the container
### docker tag
Rename images without rebuilding them
## [[OWASP]] Security Cheat Sheet
https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html