ติดตั้ง docker on WSL

Follow all these steps for in stall docker on WSL

  • 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
  • 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

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
  • Check docker version

$ docker -v
$ docker info
  • Test docker

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

    $ docker run hello-world

  • If you have error like this


    ----------------------------------------------------------------------------
    WARNING: Error loading config file: /home/user/.docker/config.json -
    stat /home/user/.docker/config.json: permission denied
    -----------------------------------------------------------------------------
  • You need to follow these commands

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

  • Test docker run again

$ docker run hello-world
  • If you have an error: Cannot connect to the docker daemon, you can follow these commands to fix this problem

$ sudo systemctl enable docker
$ sudo systemctl start docker
  • Open and test docker again

    • Open docker

     $ sudo dockerd &
    • Test docker

    $ sudo docker run hello-world
    ## Check containers
  • Show both run and stop container

$ docker ps -a
  • Check images

$ docker images

Reference:

Last updated

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University