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. ?
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?.
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.
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.
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
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:
Once these features are enabled, you’re ready to proceed with the Docker installation. ?
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. ?
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.
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]
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! ?
Install linux in windows
Docker in windows by docker doc
The above is the detailed content of Docker on Windows: Led Into Container Wonderland. For more information, please follow other related articles on the PHP Chinese website!