DEV Community

Cover image for Developer Journal..“My First Docker + Nginx Setup on Ubuntu”
Lau!
Lau!

Posted on

Developer Journal..“My First Docker + Nginx Setup on Ubuntu”

Hello Everyone!

A while ago, I decided to learn Docker and, honestly, it turned out to be much simpler than I expected. In this article, I’ll walk you through how I configured Docker on Windows using WSL (Windows Subsystem for Linux) and ran my very first container.

If you're a developer using Windows and want to get into Docker, this post is for you.

Spoiler: At the end, you’ll see the Nginx welcome page in your browser — and that feeling is amazing 🎉

What is Docker? (In Simple Terms)

Docker is a platform that allows you to package your application inside a “container” — an isolated and portable environment that behaves the same way on any machine.

Think of it as a sealed box containing everything your app needs to run.

Prerequisites

Before getting started, you’ll need:

✅ Windows 10 or 11
✅ WSL (Windows Subsystem for Linux) enabled
✅ A Linux distribution installed (we’ll use Ubuntu)
✅ PowerShell running as Administrator
Step 1: Verify and Install WSL

WSL allows you to run Linux commands directly on Windows. Let’s first verify whether it’s installed.

Option A: List all available distributions
wsl --list --online

This command will show all Linux distributions available for installation.

Option B: Install Ubuntu on WSL (if you don’t already have it)
wsl --install -d Ubuntu
Option C: Check installed distributions
wsl --list --verbose

This command is very useful because it shows the state and version of each installed distribution.

Step 2: Open Ubuntu in WSL

From PowerShell, type:

wsl -d Ubuntu

You should see something like:

user@PC:~$

Congratulations! You are now inside Ubuntu. From this point on, all commands will be Linux commands.

Step 3: Verify and Install Docker

First, let’s check if Docker is already installed:

docker --version

If Docker is not installed, you’ll see a message suggesting available packages. Install it with:

sudo apt-get install docker.io -y

The -y flag automatically answers “yes” to confirmation prompts, saving time.

Verify the installation
docker --version

You should see something like:

Docker version 24.0.x
Step 4: Enable and Start the Docker Service

Docker is now installed, but we still need to start the service.

Enable Docker to start automatically
sudo systemctl enable docker
Start the service immediately
sudo systemctl start docker
Step 5: Fix Permission Errors

If you encounter an error like this while running Docker commands:

PERMISSION DENIED WHILE TRYING TO CONNECT TO THE DOCKER API AT UNIX:///VAR/RUN/DOCKER.SOCK

Don’t worry! This is completely normal. Docker requires special permissions.

Add your user to the Docker group:

sudo usermod -aG docker your_user

Replace your_user with your Linux username.

Now you have two options:
Option 1 (Recommended): Close and reopen Ubuntu
exit

Then reopen it from PowerShell:

wsl -d Ubuntu
Option 2: Activate the group immediately
newgrp docker
Verify everything works
docker ps

If you see an empty table with headers like CONTAINER ID, IMAGE, etc., Docker is working correctly 🎉

Step 6: Run Your First Container (Nginx)

Here comes the fun part. Let’s run Nginx, one of the most popular web servers:

docker run -d -p 8080:80 nginx
What does this command do?
docker run → Runs a container
-d → Runs it in detached mode (background)
-p 8080:80 → Maps port 8080 on your machine to port 80 inside the container
nginx → The image you want to run (Docker will download it automatically)

You should see something similar to:

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
...
Digest: sha256:abc123...
Status: Downloaded newer image for nginx:latest
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6

That last string is your container ID.

Your container is now running 🚀

Step 7: Verify the Container is Running
docker ps

You should see your container listed with the status Up.

Step 8: The Best Part — Open it in Your Browser

Open any browser on Windows (Chrome, Firefox, Edge, etc.) and go to:

http://localhost:8080

If everything worked correctly, you’ll see the beautiful Nginx welcome page saying:

“Welcome to nginx!”

That feeling when you realize everything is actually working is incredible 🚀

Additional Useful Commands

Here are a few Docker commands you’ll probably want to know:

View all containers (including stopped ones)
docker ps -a
Stop a container
docker stop CONTAINER_ID
Remove a container
docker rm CONTAINER_ID
View container logs
docker logs CONTAINER_ID
Lessons Learned

✅ WSL is essential: Without WSL, Docker on Windows can feel complicated. With WSL, the experience becomes much smoother.

✅ Permissions matter: “Permission Denied” errors are completely normal. It’s not a broken installation — you just need the correct user group permissions.

✅ Docker is beginner-friendly: The Docker ecosystem has done an excellent job making containerization accessible.

✅ Documentation is your best friend: If something breaks, check the logs using docker logs.

What’s Next?

Now that Docker is working, you can:

Build your own Dockerfile for a personal application
Explore Docker Hub and discover thousands of pre-configured images
Learn Docker Compose for multi-container orchestration
Publish your own images on Docker Hub
Final Thoughts

My first experience with Docker on Windows was honestly great.

The process is clear, well documented, and most importantly — you get immediate results. And that’s one of the best ways to learn.

If you’re thinking about learning Docker:

Don’t wait any longer.

The journey into containerization begins with a simple:

docker run

Have questions? Ran into problems? Share your experience in the comments — I’d love to hear about your first Docker setup too 💙

References & Resources
Docker Official Documentation
WSL Documentation
Docker Hub

Top comments (0)