Skip to content

Latest commit

 

History

History
142 lines (105 loc) · 4.65 KB

docker.md

File metadata and controls

142 lines (105 loc) · 4.65 KB

Docker

Install docker engine and docker compose plugin on Ubuntu 22.04

  1. Set up Docker's apt repository.
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] 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
  1. Install the Docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Fix docker permission
sudo usermod -aG docker $USER

You need to reboot to apply the change

  1. Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

  1. Verify that Docker Compose is installed correctly by checking the version.
docker compose version
# Expected output:
Docker Compose version vN.N.N
# Where vN.N.N is placeholder text standing in for the latest version.

Instructions taken from docker official install guide and compose plugin install guide.

Update Docker version

To check your current Docker Engine version use the command : docker version

1. Remove the old installation

sudo apt remove docker.io docker-compose docker-doc containerd runc

2. Install dependencies

sudo apt install ca-certificates curl

3. Add the official GPG key

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

4. Add the official repository

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

5. Update and install

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Now check again the version which should be the latest version.

Clean unused docker images and volumes

First you can scan how much disk space docker used with the following command :

docker system df

If you need to make some space on your machine because your docker related files take too much space, you can run the following commands to clean your system :

# Remove all unused containers, networks, images (both dangling and unreferenced)
# https://docs.docker.com/engine/reference/commandline/system_prune/
docker system prune -a
# Remove all unused local volumes. Unused local volumes are those which are not referenced by any containers. By default, it only removes anonymous volumes.
# https://docs.docker.com/engine/reference/commandline/volume_prune/
docker volumes prune -a

Monitor CVE and lint format on Dockerfile

Like the application code, the Dockerfile and the image it builds must be audited. Three tools are wired in the Makefile for that purpose:

  • hadolint : lints the Dockerfile syntax and best practices.
  • dockle : checks the built image against container security best practices (setuid binaries, root user, secrets, ...).
  • osv-scanner : lists the known vulnerabilities (CVE) of the system and PHP packages installed in the image.

All tools are run through their own docker image so there are no install setup requirement.

# Run the three scans at once
make docker-scan

# Or run them individually
make docker-lint
make docker-scan-dockle
make docker-scan-osv

# Same OSV scan served as an HTML report on http://localhost:8000/
make docker-scan-osv-html

The scans run on the image built by make build, so rebuild it before scanning to audit your latest changes.

Accepted dockle exceptions are listed and justified in the .dockleignore file at the project root. Any new finding must be fixed rather than appended to that file.