Logo

dev-resources.site

for different kinds of informations.

Docker on Windows: Led Into Container Wonderland

Published at
9/1/2024
Categories
docker
javascript
nextjs
tutorial
Author
Bro Karim
Categories
4 categories in total
docker
open
javascript
open
nextjs
open
tutorial
open
Docker on Windows: Led Into Container Wonderland

It all started with a simple curiosity. I came across this cool open-source project made with Next.jsā€”something I was excited to explore. But then, hidden in the project files... the mysterious docker-compose.yml file.

After a quick Google search, I learned this wasnā€™t just some random file sitting there for decoration. No, no, it was essential! And to run this project, I needed Docker, the magical tool that everyone seemed to know about but never explained in simple terms.

So, my journey beganā€”installing Docker on Windows, navigating a few challenges along the way, and eventually learning that Docker is like packing your app into a shipping container, ready to sail smoothly across any platform. šŸš¢ But first, I had to figure out how to actually install the thingā€¦ and hereā€™s how that went. šŸ˜…

Mission 1 : Install wsl

So, the first stop on my Docker journey? WSLā€”aka, the Windows Subsystem for Linux. If youā€™re unfamiliar with WSL, think of it as a secret door that lets you run a full Linux environment inside your Windows machine.

I quickly learned that Docker plays really well with Linux, so installing WSL was my ticket to getting Docker up and running smoothly on Windows. My tool of choice? The mighty PowerShell! šŸ–„ļø With one simple command, I summoned WSL:

wsl --install

If everything goes well, Windows will work its magic and install the default Linux distribution, which is Ubuntu! šŸ§

Now, this is where things got interesting. The first time Ubuntu launches, it asks for a username and password. In a flash of brilliance (or laziness), I decided to keep things simple: 'ubuntu' for both the username and password.

After a brief moment, I found myself at the Ubuntu command line. But since weā€™re just getting started, the next step was to gracefully exit. To do that, I typed:

exit

ā€¦and just like that, the Linux command line window closed.

Now, if youā€™re feeling adventurous and want to try something other than Ubuntu, donā€™t worryā€”WSL gives you options! You can list all available distributions with:

wsl -l -o

And switch to a different one by running:

wsl --install -d <Distribution Name>

But for now, weā€™ll stick with Ubuntu (I mean, I already committed to the username and password, right? šŸ˜†).

Before we move forward, letā€™s make sure weā€™re using the right version of WSL. You can check which version you have installed with:

wsl -l -v

If youā€™ve got WSL 2, awesome! Itā€™s faster, more powerful, and overall a better choice for Docker. Letā€™s make it the default by running:

wsl --set-default-version 2

And just like that, the first requirement for installing Docker is complete! Weā€™re one step closer to containerized gloryšŸš¢.

Mission 2 : Donwload docker

With WSL set up and ready, it was time to tackle the next big mission: installing Docker itself. šŸ³ But before diving headfirst into the download, I had to make sure my trusty device was up to the challenge. Docker doesnā€™t run on just any old machine, after allā€”it has a few requirements youā€™ll need to meet.

1ļøāƒ£Check the System Requirements

First, I visited the official Docker website to grab the installer. But before hitting that download button, I double-checked that my device met Dockerā€™s system requirements.

Image description

These requirements include things like sufficient memory, disk space, and, importantly, a Windows build of 1900 or higher. You can check your Windows build by running the dxdiag command, which will show you all the juicy details about your system.

Image description

2ļøāƒ£Virtualization ā€“ Itā€™s a Must!

Next, I made sure that virtualization was enabled on my machine. Docker relies on virtualization to create its containers, so this step is crucial. You can check whether itā€™s enabled by opening the Task Manager and looking for the virtualization status under the "Performance" tab.

Image description

If itā€™s enabled, youā€™re good to go! If notā€¦ well, itā€™s time to take a trip to your BIOS settings and turn it on, check this out

3ļøāƒ£Enable Windows Features

Before installing Docker, there are a couple of important Windows features that need to be activated: Windows Subsystem for Linux and Virtual Machine Platform. These are essential for Docker to run smoothly.

Image description

Hereā€™s how to activate them:

  • Open the run system and type 'windows featuere'
  • Scroll through the list and check the boxes for:
    • Windows Subsystem for Linux
    • Virtual Machine Platform
  • Click OK and let Windows do its thing. Youā€™ll probably need to restart your computer to apply these changes.

Once these features are enabled, youā€™re ready to proceed with the Docker installation. šŸš€

4ļøāƒ£Download and Install Docker

Now that my system was fully prepped, I went ahead and downloaded the Docker installer from the official website. The installation process was smoothā€”just a few clicks, and Docker was up and running on my PC. šŸŽ‰

5ļøāƒ£Fire Up Docker

With Docker successfully installed, I launched Docker Desktop, and just like that, my system was ready to start spinning up containers like a pro. šŸš¢

And there we have itā€”mission two complete! Docker is now installed, next Iā€™ll walk you through setting up your first Docker container and running your Next.js project inside it.

Final Mission : Start Docker

With Docker installed and ready to roll, it was time for the final mission: testing the installation. I was about to take my first dive into containerized waters, and luckily, Docker provided a handy little lifeboatā€”a sample project called docker/welcome-to-docker. šŸ›³ļø

Step 1: Launch Docker Desktop
First things first, I launched Docker Desktop from the Start menu. Youā€™ll notice Docker starts running in the background, quietly preparing to do its container magic.

Step 2: Accessing the CLI
Now, it was time to get my hands dirty with some command-line interface (CLI) action. Since Docker works best with Linux distributions, I needed to make sure I was operating in the right environment. In my case, that meant switching to Ubuntu (remember we already exit just nowā˜ŗļø).

To switch to Ubuntu, I opened my CLI and typed:

ubuntu

This moved me into my Ubuntu environment, where Docker commands are at home. šŸ§šŸ’»

Step 3: Running the Docker Welcome Project
With the environment set, it was time to spin up my first Docker container using Dockerā€™s welcome project. Hereā€™s the command I used:

docker run -d -p 80:80 docker/welcome-to-docker

(Note: The -d flag runs the container in detached mode, meaning it runs in the background, and the -p 80:80 part maps the containerā€™s port 80 to my machineā€™s port 80. Translation: the container is now accessible via my web browser.)

Image description
After running this command, Docker fired up the welcome container in the background, and I could visit http://localhost in my browser to see the "Welcome to Docker" message. Success! šŸŽ‰

Step 4: Stopping the Container
Once Iā€™d taken in all the glory of my first running container, it was time to shut it down. To do this, I needed the containerā€™s ID. I found it by running:

docker ps -a

This listed all running containers, and from there, I grabbed the container ID. With the ID in hand, I issued the command:

docker stop [container_id]

And just like that, my container was stopped, quietly resting until needed again. šŸ›Œ

So there you have itā€”Docker is now installed on Windows. If you found this blog post helpful, feel free to share it with others who might benefit from it. And hey, why not hit that follow button for more nerdy goodness on JavaScript, React, and all things web development?

Let's stay in touch on Instagram, Twitter, and GitHubā€”where the real magic happens.

Thanks for sticking around! šŸ˜Š

Reference

Featured ones: