How to Use Docker in Windows without Docker Desktop by WSL and Docker Engine

Won Woo William Lyu·2022년 3월 31일
0

Docker

목록 보기
1/2
post-thumbnail

Before Starting,

This article is based on a personal experience.

Being a newbie to the docker, I might be wrong on some stuffs!

Please feel free to correct me through the comment!

Why Use Docker Engine, instead of Docker Desktop?

For personal, education, non-commercial or small business(fewer than 250 employess and less than $10 million in annual revenue) use, Docker Desktop is free in Windows.

So you don't have to read this article and just go download Docker Desktop.

For those who are not belong to above groups, you have to pay to use Docker Dekstop.

But what if you don't want to pay and use Docker in Windows?

You can do this by installing Docker Engine. But there is requirements to do before starting.

Prerequisite

  1. Set Up WSL(Windows Subsystem for Linux)

    • Enable Allowing WSL in your Computer

      • Control Panel > Programs > Programs and Features > Turn Windows features on or off

      • Click box on Windows Subsystem for Linux

      • Or run below command on Cmd or Powershell that is running as administrator

        $ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 
        
  2. Install Windows Terminal (Optional) and Linux System (Essential) from Microsoft Store

    • Windows Terminal (Optional)
      • Allows to use various types of terminals such as cmd, powershell or others with multiple tabs.
      • Prefer to use this application when multiple servers run simultaneously
    • Linux System (Essential)
      • Linux System is essential to run WSL
      • Personally, I downloaded Ubuntu since I am familiar with it, but you can download any linux system that is in Microsoft Store.
      • After downloading linux system, start the linux program and set the user and password

After Completing Step 1 and 2, you can finally use wsl in your computer.

Install Docker Engine

Installing Docker Engine is pretty simple.

You just have to go to below link and follow the guideline that the docker is providing.
https://docs.docker.com/engine/install/ubuntu/

Since it can be confusing, I will write down How I installed a docker engine in my computer, but it will be very similar to what is written in above documentation

  1. Set up the Repository
  • Below command will update apt package index, and it is recommended to use this command once a week in a linux if you want to update your linux packages to latest version since linux does not automatically update its package like Windows
    $ sudo apt-get update
  • Below command will allow apt to use a repository over HTTPS
    $ sudo apt-get install \
         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
  • Set up stable repository.
        $ echo \ 
        "deb [arch=$(dpkg --print-architecture) 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
    • If you want to download nightly or test or both repository, just add each or both word after stable in above command.
      • stable : latest releases for general availability
      • nightly : latest builds of work in progress for the next major release
      • test : pre-releases that are ready for testing before general availability (GA)
  1. Install Docker Engine
  • Update apt package index
    $ sudo apt-get update
  • Install the latest version of Docker Engine and containerd.
    $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    • If you want to download specific version, run below command with specific version
      $  sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
    • You can list version that is available in your repo with below command
      $ apt-cache madison docker-ce

Run Docker Daemon and Test Docker Engine

Following above instructions, you are done with installing docker engine in your WSL.

It is time to test if docker engine works correctly by running hellow-world cotainer!

However, there is one more thing to discuss. Docker Daemon!

What is Docker Daemon?

Docker daemon is a persistent background process that manages the containers on a single host, which means that docker daemon needs to be run before running any container.

Below command will run docker daemon, and you must keep running it to use any container.

$ sudo dockerd &

& makes command run in background in linux

Run Hello-World Container

With running docker daemon in a background, run below code which will run hello-world container.

sudo docker run hello-world

Output

If the result is same as above picture, then you successully run hello-world with docker!

Small Tips on Docker Daemon

If you get below error, when you try to start a docker daemon,

$ failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid

run below code and rerun docker daemon

$ sudo killall -9 dockerd

Above error occurs, because you are trying to run docker daemon when docker daemon is already running.
-9 stands for sigkill and the solving command will kill all signal related to docker daemon.

profile
Hello!! I am an ENFP Backend Engineer!!

0개의 댓글