As of Jul 3, 2023, there was an issue when following the instructions to install docker in the Windows 10 WSL2. The resolution was to remove all the docker from the Ubuntu, then installed using the deb package as described in the following link: https://docs.docker.com/engine/install/debian/#install-from-a-package
There are several types of installation including: Docker Engine, Docker Desktop, and Docker Compose.
Docker Engine is an open source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with:
- A server with a long-running daemon process dockerd
- APIs which specify interfaces that programs can use to talk to and instruct the Docker daemon
- A command line interface (CLI) client docker.
Docker Desktop is an application for Mac or Windows environment that enables you to build and share containerized applications and microservices. It provides a simple interface that enables you to manage your containers, applications, and images directly from your machine without having to use the CLI to perform core actions. It includes:
- Docker Engine
- Docker CLI client
- Docker Compose
- Docker Content Trust
- Kubernetes Credential Helper
Docker Compose is Compose is a tool for defining and running multi-container Docker applications.
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
$
[Optional] Uninstall old versions of Docker (if installed) including: docker, docker.io, or docker-engine; Note: the contents of /var/lib/docker/, including images, containers, volumes, and networks, are preserved.
Setup the repository to pull the binary from - there are different methods to install docker: install using the repository (recommended), install from a package, and install using the convenience script (for development environments quickly).
Install docker engine
Verify installation
Post install for Windows WSL2 - Ubuntu; also need to be done after windows reboot otherwise "WSL2 Error...", as shown below.
Post install - during installation the docker group is created but no users are added to it. You need to use sudo to run Docker commands. The following setup allows non-privileged users to run Docker commands. NOTE: not needed for WSL setup.
How-to
WSL2 Error: docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
The above step, "Post install for Windows WSL2 - Ubuntu", is needed to start the docker service in the WSL2 Ubuntu environment, otherwise the error.
NOTE: this error happens after first install as well as after windows reboot.
Docker Registry
Setup account with one of the following providers, and make sure to check the pricing.
$ sudo apt-get update
// install packages to allow apt to use a repository over HTTPS
$ sudo apt-get install ca-certificates curl gnupg lsb-release
// add Docker’s official GPG key
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
// set up the repository
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
// install the latest version of Docker Engine, containerd, and Docker Compose
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
[...]
For more examples and ideas, visit:
https://docs.docker.com/get-started/
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 10 months ago 13.3kB
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ sudo service docker start
* Starting Docker: docker [ OK ]
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
// just in case, but docker group should have been created
$ cat /etc/group | grep docker
docker:x:999:
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
// if the following does not work; try logout or restart
$ newgrp docker
// verify running not as root
$ docker run hello-world