> For the complete documentation index, see [llms.txt](https://docs.aic-eec.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aic-eec.com/c-c++-for-embedded-programming/development-environment-preparation/docker-on-wsl.md).

# ติดตั้ง docker on WSL

### Follow all these steps for in stall docker on WSL&#x20;

* Update your system

```
$ sudo apt-get update && sudo apt-get upgrade
```

* Install necessary package using with docker

```

$ sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        gnupg \
        lsb-release
```

* &#x20;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

$ echo \
      "deb [arch=amd64 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 docker&#x20;

```
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
```

* Check docker version

```
$ docker -v
$ docker info
```

* Test docker&#x20;

```
sudo docker run hello-world
```

* If it does not work please add package group to your user

  * Add package group to user

  ```
  $ sudo groupadd docker
  $ sudo usermod -aG docker $USER
  $ newgrp docker
  ```

  * Test docker on user&#x20;

  ```
  $ docker run hello-world
  ```

* <mark style="color:red;">If you have error like this</mark>

```

    ----------------------------------------------------------------------------
    WARNING: Error loading config file: /home/user/.docker/config.json -
    stat /home/user/.docker/config.json: permission denied
    -----------------------------------------------------------------------------
```

* <mark style="color:red;">You need to follow these commands</mark>

```
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "$HOME/.docker" -R
```

* Test docker run again&#x20;

```
$ docker run hello-world
```

* If you have an error: <mark style="color:red;">Cannot connect to the docker daemon</mark>, you can follow these commands to fix this problem

```
$ sudo systemctl enable docker
$ sudo systemctl start docker
```

* Open and test docker again&#x20;

  * Open docker

  ```
   $ sudo dockerd &
  ```

  * Test docker&#x20;

  ```
  $ sudo docker run hello-world
  ## Check containers
  ```
* Show both run and stop container&#x20;

```
$ docker ps -a
```

* Check images

```
$ docker images
```

Reference:&#x20;

{% embed url="<https://docs.docker.com/engine/reference/commandline/ps>" %}
