Home > Web Front-end > JS Tutorial > Docker on Windows: Led Into Container Wonderland

Docker on Windows: Led Into Container Wonderland

WBOY
Release: 2024-09-01 21:03:07
Original
603 people have browsed it

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.

Docker on Windows: Led Into Container Wonderland

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
Copy after login

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
Copy after login

…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
Copy after login

And switch to a different one by running:

wsl --install -d <Distribution Name>
Copy after login

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
Copy after login

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
Copy after login

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.

Docker on Windows: Led Into Container Wonderland

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.

Docker on Windows: Led Into Container Wonderland

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.

Docker on Windows: Led Into Container Wonderland

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.

Docker on Windows: Led Into Container Wonderland

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
Copy after login

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
Copy after login

(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.)

Docker on Windows: Led Into Container Wonderland
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
Copy after login

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]
Copy after login

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! ?
Docker on Windows: Led Into Container Wonderland

Reference

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

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template