2 Containerizing Your App

 

This chapter covers:

  • How to containerize apps
  • Running your container locally
  • Executing commands in the container context

Containerizing your application, that is, packaging your application and its dependencies into an executable container is a required step before adopting Kubernetes. The good news is that containerizing your application has benefits beyond being able to deploy it into Kubernetes, it’s a valuable step on its own right, as you’re packaging up the application’s dependencies and can then run it anywhere without needing to install those dependencies on the host machine.

Regardless of how you deploy your app, containerizing it means that your developers can start working on it locally using Docker, enabling them to get started on a new project with no setup beyond installing Docker. It provides easy context switching between the different applications developers are working on, as the environments are completely isolated. These properties make it a valuable way to improve developer productivity even if you don’t end up deploying your app into production with containers (though you’ll probably want to do that too).

Figure: Comparison of multiple projects on a development machine with and without containerization.

2.1      Building the Dockerfile

2.1.1   Language-specific Base Images

2.1.2   Specifying the Default Command in the Dockerfile

2.1.3   Adding Dependencies

2.1.4   Compiling Code

2.2      Developing a Server Application with Docker

2.2.1   Running One-off Commands

2.2.2   Containerizing Our Application Server

2.2.3   When Things Go Wrong

2.3      Capturing Runtime Configuration with Docker Compose

2.3.1   Adding Service Dependencies

2.3.2   Mapping Folders Locally

2.3.3   Faking External Dependencies

sitemap