dev-resources.site
for different kinds of informations.
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.
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.
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.
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.
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.)
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: