Docker for Web Developers

Do you need Docker?

1,000 words, 5-minute read

Does our web development stack really need another technology?

Modern web development involves a deluge of files, systems, and components:

Managing this stack can be a challenge.

How many hours do you spend installing, configuring, updating, and managing software dependencies on your development PC?

“It works on my machine, buddy” #

Imagine your latest application has become successful. You’ve had to hire another developer to give you more time to rake in money. They turn up at work on day one, clone your repository, launch the code, and – BANG – it fails with an obscure error message.

Debugging may help, but your environments are not the same…

The differences mount up.

You may be able to solve these issues within a few hours, but…

Some companies would implement a locked-down device policy, where you’re prevented from using the latest or most appropriate tools. (Please don’t be that boss!)

Virtual machining #

Rather than restricting devices and software, the application could be run within a Virtual Machine (VM). A VM allows an operating system to be installed in an emulated hardware environment; in essence, it’s a PC running on your PC.

Cross-platform VM options include VMware and VirtualBox. You could create a Linux (or other) VM with your application and all its dependencies. The VM is just data: it can be copied and run on any real Windows, macOS, or Linux device. Every developer – and the live server – could run the same environment.

Unfortunately, VMs quickly become impractical:

Docker delivers #

Docker solves all these problems and more. Rather than installing dependencies on your PC, you run them in lightweight isolated VM-like environments known as containers.

In a single command, you can download, configure, and run whatever combination of services or platforms you require. Yes, a single command. (Admittedly, it can be quite a complicated command, but that’s where this book comes in!)

Development benefits include:

Similar Docker environments can also be deployed in production:

Nah, I’m still not convinced #

Neither was I.

When I first encountered Docker, it seemed like an unnecessary and somewhat daunting hurdle. I had plenty of experience running VMs and configuring software dependencies – surely I didn’t need it?

Docker documentation is comprehensive but it has a steep learning curve. Tutorials are often poor and:

  1. presume the reader fully understands all the jargon,

  2. fail to explain or over-explain esoteric points, and

  3. rarely address how Docker can be used during development.

    When I started, I presumed Docker couldn’t handle dynamic application restarts or debugging. Tutorials often claimed every code change required a slow and cumbersome application rebuild.

I gave up.

I was eventually shown the light by another developer (thanks Glynne!) That led to several months deep-diving into Docker and I realised what I’d been missing.

Example: I’ve created many WordPress-based websites.

I’d usually develop these directly on Windows or an Ubuntu VM, where it’s necessary to install/update Apache, SSL, PHP, MySQL, and WordPress itself. All before commencing the real development work.

The equivalent Docker process takes minutes to initialize and can be cloned for every new project (see WordPress development with Docker). Each installation exists in its own isolated environment which can be source-controlled and distributed to other developers.

That said, I’ve never deployed WordPress to a production server using Docker. WordPress hosting is ubiquitous and inexpensive; I’m happy to let someone else manage those dependencies. However, potential problems are minimized because I replicated the production server environment on my development PC.

It is considerably easier to build applications with Docker. Without wanting to sound like a salesperson, Docker will revolutionize your development!

Isn’t {insert-technology-here} where it’s at? #

Docker helps regardless of which web development approach and stack you’re using. It provides a consistent environment at build time and/or closely matches the dependencies on your production server(s).

Your Docker environment:

  1. works without an active/fast internet connection (useful when travelling, during demonstrations, etc.)
  2. permits experimentation without risk. No one will mind if you accidentally wipe your local MySQL database.
  3. is free from cost and usage restrictions.

Monolithic web applications #

Monolithic applications contain a mix of front-end and back-end code. Typically, the application uses a web server, server language runtime, data stores, and client-side HTML, CSS, JavaScript and frameworks to render pages and provide APIs. WordPress is a typical example.

Docker can be used to replicate that environment so all dependencies are available on your development PC.

Serverless web applications #

Serverless applications implement most functionality in the browser typically with a JavaScript framework to create a Single Page Application (SPA). The core site/application is downloaded once.

Additional data and services are provided by small APIs perhaps running as serverless functions. Despite the name, servers are still used – but you don’t need to worry about managing them. You create a function which is launched on demand from a JavaScript Ajax request, e.g. code that emails form data to a sales team.

Docker can be used in development environments to:

  1. run build processes such as JavaScript module bundling and Sass preprocessing
  2. serve the web application, and
  3. emulate infrastructures for serverless function testing.

Static sites #

A static site is constructed using a build process which places content (markdown files, JSON data, database fields, etc.) into templates to create folders of static HTML, CSS, JavaScript, and media files. Those pre-rendered files can be deployed anywhere: no server-side runtime or database is required.

Static sites are often referred to as the JAMstack (JavaScript, APIs, and Markdown). All content is pre-rendered where possible, but dynamic services such as a site search can adopt server-based APIs.

Docker can be used to provide a reproducible build environment on any development PC.

Key points #

What you’ve learned in this chapter:

  1. Docker can launch all your application’s dependencies in individual containers.

    This includes servers, databases, language runtimes, etc. In most cases, these will require little or no configuration.

  2. Docker is cross-platform.

    It runs on Windows, macOS, and Linux. Your application will work on any PC.

  3. Docker can – and should – be used in your development environment.

    You can also use it in production systems if it’s practical to do so.

The next chapter describes Docker concepts in more detail.


Do you want an easy-to-follow course which demonstrates how to use Docker and create practical web development environments on your Windows, macOS, or Linux PC?

Buy the "Docker for Web Developers" book & video course…

plus your country's sales tax where applicable

HALF PRICE SALE NOW ON!