# ติดตั้ง 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>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/c-c++-for-embedded-programming/development-environment-preparation/docker-on-wsl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
