There are different ways to use docker. For example:
- Docker desktop - for development purposes available on Windows, Max and Linux. Contains more than the docker engine and docker compose. It is free for personal use and learning. Not suitable for server environment.
- Docker engine and docker compose - suitable for server environment, can be used for development purposes.
This document summarizes installation and setup of Docker engine and docker compose on Linux and Windows. Contents:
- Install Docker Engine and Docker Compose in Linux - summarizes installation steps of docker engine and docker compose in Ubuntu linux.
- Docker on Windows - summarizes usage scenarios and touches on some windows related specifics
- Install Docker engine and docker compose in wsl distribution -
summarizes installation of wsl, installing docker engine and docker compose in wsl distribution.
- Working with WSL - summarizes
To install docker, follow the instructions below:
- Note: Copy and paste all shell commands in each code block. Do not copy and paste the commands in a code block line by line.
- https://docs.docker.com/engine/install/ubuntu/
- Note: If you do not have Ubuntu check installing on a different linux distributions here https://docs.docker.com/engine/install/
- https://docs.docker.com/compose/install/standalone/
-
Start docker:
> sudo service docker start
-
Check docker service is running
> sudo docker ps
see Add username to docker group if permission deniedor
> sudo service docker status
-
find out your username
> whoami
output:
> your_username
-
add
your_username
to groupdocker
:> sudo usermod -a -G docker your_username
-
exit the command line. Note, this is important because the effect of adding the username to the group docker will be visible only in a new shell.
Docker can be installed and used on windows in several ways. For example:
- Using docker directly from windows
- Using docker from a wsl distribution
Combining these two scenarios with the two scenarios from section Using Docker
- Docker desktop installed directly on windows.
- Docker engine and docker compose installed directly on windows. Should be possible, not tested.
- Docker desktop installed in a wsl distribution. Should be possible, not tested.
- Docker engine and docker compose installed in a wsl distribution.
Scenario 1. Docker creates two wsl distributions docker-desktop-data
and docker-desktop
to enable running linux
docker images on windows. Not sure how wsl is used in scenario 2.
Scenario 3. and 4. a linux distribution is installed in wsl and docker components are installed inside.
It all scenarios host paths when mapping volumes should use a prefix:
- For docker installed in windows (not in wsl distribution) (scenarios 1. and 2.) - host paths should be prefixed with
/host_mnt/
. For exmaple,/host_mnt/c/users/user1
. - For docker installed in windows in wsl distribution (scenarios 3. and 4.) - host paths should be prefixed with
/mnt/
. For exmaple,/mnt/c/users/user1
.
Scenario 1. is the simplest. To setup scenario 3. see Install Docker engine and docker compose in wsl distribution.
-
Install wsl and a linux distribution - see section Install WSL
-
Install docker engine and docker compose in WSL
-
Enter a linux distribution in wsl
> wsl -d Ubuntu-22.04
-
Follow instructions in section Installation of docker in WSL should be the same as installing docker on linux.
-
This section summarizes installation and usage of WSL.
Install wsl and a linux distribution
-
Install wsl - See section "Install WSL command" in https://learn.microsoft.com/en-us/windows/wsl/install
-
Install Ubuntu distribution (e.g. Ubuntu-22.04) - see section "Change the default Linux distribution installed" in https://learn.microsoft.com/en-us/windows/wsl/install.
Note: Alternatively WSL and the distribution can be installed from the Microsoft store.
Control resources dedicated to wsl
-
Create file "c:/users//.wslconfig"
-
set resources :
[wsl2] memory=6GB processors=4
-
for more info see https://learn.microsoft.com/en-us/windows/wsl/wsl-config
Some useful wsl commands:
-
Wsl help
> wsl --help
-
List installed distributions
> wsl -l (same as wsl --list)
-
List distributions available online
> wsl -l -o (same as wsl --list -online)
-
Install distribution
> wsl --install Ubuntu-22.04
-
enter distribution
> wsl -d Ubuntu-22.04 (same as wsl -distribution Ubuntu-22.04)