Docker’s advantages are easy for Web developers to overlook. It was considered too technical and unnecessary for development operations. Terminology can be difficult to understand. The tutorial never explains how to use Docker during development. Here take you to feel the application of Docker in WEB development.

Let’s start by looking at the technologies that might be involved in the WEB development process

  • HTMLContent and Templates
  • CSSStyle sheets and preprocessors, such as Sass
  • The front endJavaScriptIncluding, for example,React.Vue.jsandSvelteOr something like that
  • Build tools, for examplebundlers,minifiers,etc.
  • Web server, for exampleNGINXorApache
  • Server side and framework, includingNode.js.PHP.Python.Ruby..NETAnd so on.
  • Database, for exampleMySQL,MariaDB,SQL ServerorMongoDB
  • Other services for caching, message queuing, E-mail, process monitoring, and so on.
  • Git and Github are used for source control
  • Managing these can be quite a challenge.

It would take at least a few hours to install and configure the above environment during development!

1.1. “It works on my machine, buddy.”

Imagine that your recent application has been very successful. You have to hire another developer to give you more time to make money.

They show up on the first day of work, clone your code base, launch the code, and bam, it fails with a vague error message.

Debugging can be helpful, but your environment is different…

  • You use Mac, they use Windows
  • You are developing your application using Node.js V10 with V14 installed
  • You are using MongoDB V3.6, they are on V4.2

The differences increase.

It may be possible to solve these problems in a few hours, but…

  • Can I keep each dependency in sync?
  • Is this feasible as the number of teams and devices grows?
  • Are these dependencies available on all development OS and production servers?

Some companies will implement locked-in device policies, in which case the latest or most appropriate tools will not be available. Is this what you might think of a virtual machine?

1.2. Virtual Machines

The application can run within a virtual machine (VM), rather than limiting devices and software. The VM allows the operating system to be installed in an emulated hardware environment. Essentially, it’s a PC running on your PC.

Cross-platform VM options include VMware, VirtualBox, and Parallels Desktop. In theory, you can use your application and all its dependencies to create a Linux (or other) VM. A VM is just data: it can be copied and run on any real Windows, macOS, or Linux device. Every developer and real-time server can run the same environment.

Unfortunately, virtual machines quickly become impractical:

  • VM disk images are large and difficult to copy
  • A single VM can be updated automatically or by a single developer, and therefore out of sync with other VMS
  • A VM requires a lot of computing resources: it is a complete OS running on emulated hardware within another OS.

1.3 Docker delivery

Docker solves all these problems and more. Instead of installing dependencies on a PC, you can run them in a lightweight, isolated VM-like environment called a container.

In a single command, you can download, configure, and run any combination of services or platforms you want. Yes, there is only one command. (Admittedly, this can be a very complicated command, but that’s our purpose!)

Development benefits include:

  • All developers can use the same Docker container on Mac, Linux, and Windows
  • Applications are easier to install, configure, maintain, and test
  • The application runs in a virtual environment isolated from the development PC
  • Multiple versions of the same application or runtime can be used simultaneously on the same PC, such as PHP 5.6, 7.0, 7.4, and so on.
  • Developers retain all the advantages of local development and can experiment without risk.

A similar Docker environment can also be deployed in production:

  • Continuous integration and delivery processes can be simplified for rapid deployment
  • Use horizontal scaling to improve performance. More application containers can be added to handle the increased traffic.
  • Services are more powerful. If the container fails, it can be restarted automatically with zero down time.
  • Applications can be secured. Containers can be configured to communicate only with each other and not with the outside world. You can provide the MySQL database to the WordPress container without exposing it to the host OS or later.

1.4. No, I still don’t believe it

I don’t believe it either.

When I first encountered Docker, this seemed like an unnecessary and somewhat daunting hurdle. I have extensive experience running VMS and configuring dependencies – surely not?

Docker documentation is comprehensive, but the learning curve is steep. Tutorials are often poor and:

  1. Assuming that the reader fully understands all the terminology,
  2. Inability to explain or over explain abstruse points
  3. There is little discussion of how to use Docker during development.

When I started, I didn’t think Docker could handle dynamic application reboots or debugging. Tutorials often claim that each code change requires a slow and cumbersome application rebuild. So I gave up.

Finally, another developer showed me the powerful application scenarios of Docker, which led me to study Docker in depth for several months, learning what I lacked.

1.5. Let’s see what we can do.

No matter what Web development method and stack you use, Docker can help. It provides a consistent environment at build time and/or closely matches dependencies on the production server.

Docker environment:

  1. Work with no activity/fast Internet connection (useful during travel, demo medium)
  2. Allow experimentation without risk. If you accidentally erase your local MySQL database, no one will care.
  3. There are no cost or use restrictions.

1.5.1 Overall Web application

The overall application consists of a mix of front-end and back-end code. Typically, the application uses a Web server, a server language runtime, a data store, and client-side HTML, CSS, JavaScript, and frameworks to render the page and provide apis. WordPress is a prime example.

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

1.5.2 Serverless Web Applications

Serverless applications typically implement most of the functionality in the browser using JavaScript frameworks to create single-page applications (spAs). The core site/application will be downloaded once.

Small apis may run as serverless capabilities, providing additional data and services. Despite the name, the server is still in use – but you don’t need to worry about managing it. You create a function that launches on demand from a JavaScript Ajax request, for example, code that e-mails form data to a sales team.

Docker can be used in development environments for:

  • Run build processes, such as JavaScript module bundling and Sass preprocessing
  • Service web applications, as well
  • Simulate an infrastructure for serverless functional testing.

1.5.3 static sites

Build a static site using a build process that puts content (Markdown files, JSON data, database fields, and so on) into templates to create folders containing static HTML, CSS, JavaScript, and media files. These pre-rendered files can be deployed anywhere: no server-side runtime or database is required.

Static sites are often called JAMstack (JavaScript, API, and Markdown). Everything is rendered up front where possible, but dynamic services (such as site search) can use server-based apis.

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