Docker Crash Course


Docker Crash Course

Read in your browser

Sponsored by: 1440

News. Without Motives. That’s 1440

Over 4 million readers rely on our 5-minute newsletter for a clear, fact-based view of the world. We sift through 100+ sources to bring you unbiased news on politics, global events, business, and culture. Free of charge and free of bias

With the holidays in full swing, I hope you’ve taken a moment to slow down and enjoy the season. It’s the perfect time to step back, recharge, and prepare for the exciting opportunities the new year will bring.

On my side, I'm having a great time at home with the family and kids, playing tons of video games. We almost got to the last boss in Megaman 11 and made great progress in Final Fantasy VII Rebirth (this game is so big and beautiful!).

Today I'll give you a quick intro to Docker, a wonderful piece of tech I've been using for many years now, and that really revolutionized the way we deploy things to the cloud.

Let's dive in.

What is Docker?

Let's start with a formal definition:

Docker is a platform that provides the ability to package and run an application in a loosely isolated environment called a container.

Containers are lightweight, portable environments that bundle an application with everything it needs to run—code, libraries, and dependencies.

For a concrete example, let's say I want to run the popular NGINX web server in my box.

In the past, if you wanted to run NGINX on your machine, you would have to manually install it, configure it, and ensure all its dependencies were properly set up.

This could involve downloading specific versions of NGINX, managing conflicts with existing software on your system, and dealing with potential issues caused by differences between environments (your machine vs. a production server).

Today, here's what you can do with Docker:

  1. You start by pulling the NGINX image from Docker Hub, which is a public repository of containerized applications.
  2. Once pulled, you run the image using your local version of Docker, which creates a container. Think of this as starting a lightweight, isolated version of the application.
  3. Then you can access the NGINX server from your web browser on a specified port (say, localhost:8080).

The key thing is that Docker simplifies your development cycle by ensuring your application works the same way, whether it’s on your local machine, a staging server, or in production.

Now let's walk through the commands you would use to quickly run NGINX in your box.

Getting Docker Desktop

To run any Docker container in your box, you need the Docker Engine, which is included with Docker Desktop. You can download it for free here.

After you install it, you have everything you'll ever need to run any docker image.

You will also get a nice app where you can manage your Docker images, containers, volumes, and several other things:

Now let's see how to get the NGINX Docker image to your box.

Pulling a Docker image

Where to download the NGINX Docker image from? Head to https://hub.docker.com and you will quickly find it:

That page will give you all the details about this image, including how to pull it down to your box.

So, open a terminal in your box and run this command:

It should take a few seconds, and then your image will be ready:

You will find it in your Docker Desktop Images section:

Now let's see how to run NGINX in your box via that Docker image.

Running a Docker container

When you run a Docker image we say it turns into a Docker container, and you can do it in your terminal with this command:

So, you start with docker run and you end with the name of your image, nginx in this case.

The -p 8080:80 piece is what we know as port mapping, and you use it to make the services running inside the Docker container accessible from your local machine.

Otherwise, NGINX will be running there, but you would have no way to access it.

8080 is the port you can use in your box to reach NGINX, and 80 is the port inside the container where NGINX is listening (the "container port").

You can confirm the running container in the Containers tab in Docker Desktop:

Now we are ready to browse to our web server.

Browsing to the NGINX server

Nothing special here. From the point of view of your local box, there is now an NGINX web server running at http://localhost:8080.

So all you do is point your browser to that address and you'll get the NGINX home page:

Notice how your browser doesn't really care how exactly NGINX was made available at localhost:8080; it just sees a web server responding to its requests.

This is the beauty of Docker: it abstracts away the complexities of installation, configuration, and environment-specific quirks.

Nice!

Wrapping up

I just scratched the surface there, but if you need to know more about Docker containers, like:

  • What if you want a specific version of NGINX (or any image)?
  • How to modify the HTML served by NGINX (or anything else inside the container)?
  • How to preserve your updates across container restarts?
  • How to pass environment variables to your containers?

I got all that (and more!) covered in a new Docker mini-course I include with Course 3 of the bootcamp (on sale for a few more days).

Speaking of which, I have 7 modules of that course already recorded, with 3 more to be completed next week, so I better get back to work.

Happy Holidays!

Julio


Whenever you’re ready, there are 3 ways I can help you:

  1. .NET Cloud Developer Bootcamp:​ Everything you need to build production-ready .NET applications for the Azure cloud at scale.
  2. Ultimate C# Unit Testing Bundle: A complete beginner to advanced C# unit testing package to write high-quality C# code and ship real-world applications faster and with high confidence.
  3. Promote yourself to 20,000+ subscribers by sponsoring this newsletter.

11060 236th PL NE, Redmond, WA 98053
Unsubscribe · Preferences

The .NET Saturday

Join 20,000+ subscribers for actionable .NET, C#, Azure and DevOps tips. Upgrade your skills in less than 5 mins every week.

Read more from The .NET Saturday

Fixing Claims the Right Way Read in your browser It's flu season in the US and after my 5yo went down with a cold, sure enough, one of my other kids followed and then it got me. So it's been a tough week, but hope to be recovering by the time you read this. On top of that, seems like it's time for a full Windows reinstall because this box has been giving me so much trouble lately. But before getting into that adventure, I thought it would be best to finish this newsletter, where I'll cover a...

Avoiding The DIY Authentication Trap Read in your browser With Course 3 of the bootcamp finally launched, I'm now switching gears to Course 4, which will be all about deploying .NET apps to the Azure cloud, one of the most exciting parts of the bootcamp. One key thing you need to master before doing any sort of cloud development is Docker, which I believe most developers are not using yet. That's why I spent most of this week working on tons of new Docker-specific content, learning a few new...

IsAuthenticated Is Not About The User Read in your browser A few days ago I finished the audiobook version of Nexus, the latest book by Yuval Noah Harari, and wow, it's such an impressive take on the impact of AI in our society and what could come next. One potential scenario mentioned in the book is the creation of AI-powered social credit systems, where governments or organizations score individuals based on their behaviors, decisions, and interactions. Governments today are already...