Skip to content

Latest commit

 

History

History
143 lines (84 loc) · 5.07 KB

using-docker.md

File metadata and controls

143 lines (84 loc) · 5.07 KB

Using Docker

There are different ways to use docker. For example:

  1. 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.
  2. 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

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.
  1. https://docs.docker.com/engine/install/ubuntu/
  2. https://docs.docker.com/compose/install/standalone/

Working with docker

  • Start docker:

    > sudo service docker start

  • Check docker service is running

    > sudo docker ps see Add username to docker group if permission denied

    or

    > sudo service docker status

Add username to docker group

  • find out your username

    > whoami

    output:> your_username

  • add your_username to group docker:

    > 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 on Windows

Docker can be installed and used on windows in several ways. For example:

  1. Using docker directly from windows
  2. Using docker from a wsl distribution

Combining these two scenarios with the two scenarios from section Using Docker

  1. Docker desktop installed directly on windows.
  2. Docker engine and docker compose installed directly on windows. Should be possible, not tested.
  3. Docker desktop installed in a wsl distribution. Should be possible, not tested.
  4. 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 Docker Engine and Docker Compose in WSL Distribution

  1. Install wsl and a linux distribution - see section Install WSL

  2. Install docker engine and docker compose in WSL

    1. Enter a linux distribution in wsl

      > wsl -d Ubuntu-22.04

    2. Follow instructions in section Installation of docker in WSL should be the same as installing docker on linux.

Working with WSL

This section summarizes installation and usage of WSL.

Install WSL

Install wsl and a linux distribution

  1. Install wsl - See section "Install WSL command" in https://learn.microsoft.com/en-us/windows/wsl/install

  2. 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.

Using WSL

Control resources dedicated to wsl

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)