Since its first release in 2013, Docker has quickly become one of the hottest topics in software development, and has been adopted by both large and small companies across the world. That said, there are plenty of developers who have never gotten a chance to use Docker, or been exposed to it enough to understand its benefits. In this article, we'll cover an overview of how Docker works and three examples of using Docker with Node.

What is Docker and what are containers?

Docker is a container engine. Containers are similar to virtual machines, but they don't actually emulate the whole operating system. Instead, all of the containers you run share the same underlying kernel with the host machine, which means that they're much lighter and more efficient than virtual machines. While a VM may take 1-2 minutes to start up, Docker containers take just a few seconds. Even if you're not an expert in virtualization or devops, using containers can still improve your development practices.

Docker offers developers advantages like increased modularity, an easy way to share environmental dependencies, and tools to make server configuration simpler. This makes Docker a great tool for developers working in any language, but in this blog post, we'll focus on three examples in Node. First, we'll run a simple "Hello World" script in a Docker container, then we'll move on to an Express web app, and finally, we'll add a database connection to our web app to demonstrate running and linking multiple containers.

Note: the complete code for this blog post is available on Github. You can use the start-here branch if you're following this tutorial, or the master branch if you just want to get a final working product.

1. Running a Node Script in Docker

Before you get started, install Docker for your operating system. Docker can be run on Windows, Linux, or Mac and it's free if you're using the community edition. You can make sure Docker is installed and running using the command: docker -v . If you're not using version 17.0 or greater, download the latest version before continuing.