Stepping into App Development

Learn what container-based application development is.

What to expect in this chapter?

The pre-built Docker images such as MySQL, Adminer, and WordPress are useful, but you’ll eventually want to run your own programs in a container.

In this chapter, you’ll be creating a Node.js “Hello World” application that is built into a Docker image and launched as a container. By default, the image will be ready for deployment on a production server, but Docker Compose will be used to override some settings to create a development and debugging environment. You’ll be able to edit source code on your host, but the files will be executed within a continually running container. This has several benefits:

  • Docker will manage dependencies for you – there’s no need to install and maintain language runtimes.
  • The process is a little different from developing locally.
  • The container is isolated. Your application cannot do anything like crash the host PC or wipe files.
  • You can distribute your application to other developers or testers. It will run identically on any other device with zero configuration.

Container-based application development

Docker simplifies web development. Any web application you create can be run in a single container.

However, if you want to deploy similar containers to live production servers, the application should be stateless. Any number of instances can be started and any can react to requests. In practical terms, your application should not store essential state data in local files or memory.

For example, an application stores login credentials in memory when a user logs in. A single container is used during development so everything works as expected.

The application is then deployed to a production server and run in two containers that receive requests via a load balancer. A user accesses the system and has their login processed by container1. Their next request is served by container2. It does not have the user’s state and redirects to the login page.

Get hands-on with 1200+ tech skills courses.