Dockerizing Your Development: A Guide to Navigating the Dark and Mysterious World of Containerization

Dockerizing Your Development: A Guide to Navigating the Dark and Mysterious World of Containerization

Manager: Why is it not working?
Me: It works on my computer.
Manager: *ships computer to the client*

If you have also been in a situation where your manager could ship your computer to the end user because the deployed version isn't working, then you might want to get a new computer and start doing development inside a container.

So when I say "start development inside a container", I don't mean you need to go to a shipyard & sit in a container while coding. I mean, you should start using container technologies for development.

Container Runtimes

Container runtimes are the low-level software components that manage the creation, execution, and maintenance of containers. They are responsible for managing the underlying system resources, such as CPU, memory, and storage, and ensuring that containers have access to the resources they need to run. Container runtimes also provide the necessary networking and security features, such as isolating containers from each other and the host system. Examples of container runtimes include Docker, rkt, and CRI-O. Choosing the right container runtime depends on factors such as the specific requirements of the application, the underlying infrastructure, and the development team's preferences and expertise. The choice of runtime will impact the performance, security, and overall experience of working with containers. For this article, we'll be focusing on Docker.

VS Code Devcontainer

Getting started with Visual Studio Code (VSCode) devcontainers involves the following steps:

  1. Install Visual Studio Code: If you haven't already, install the latest version of VSCode from the official website.

  2. Install the Dev Containers extension: Open VSCode and navigate to the Extensions marketplace. Search for the "Dev Containers" extension and install it.

  3. Create a container definition file: From the VSCode Command Palette (press Ctrl/Cmd + Shift + P), select the Dev Containers: Add Dev Container Configuration Files... option and select the configuration that you want, there are many predefined configurations. Let's use Alpine for now, but the steps are going to be around the same for any other. We can use a Dockerfile or a docker-compose config file too but we'll cover it in a future article. Select version and additional features you might want to add to your container. Now wait for the files to be created, VSCode will create devcontainer.json .

  4. Open the project in a devcontainer: From the VSCode Command Palette (press Ctrl/Cmd + Shift + P), select the Dev Containers: Open Folder in Container... option.

  5. Wait for the devcontainer to build: VSCode will build the devcontainer based on the configuration in devcontainer.json. This process may take a few minutes, depending on the size of the base image and the required dependencies.

  6. Start coding: Once the devcontainer is built, you'll have a fully-functional development environment within the container, ready for coding. All your project files will be accessible within the devcontainer, and any changes you make will be saved to the host file system. You can install any extensions you want in the container.

  7. Debug and test as needed: Use the VSCode debugger and test tools to develop and test your application within the devcontainer.

By using VSCode devcontainers, you can create consistent, isolated development environments that can be easily shared and replicated, speeding up your development and streamlining your workflows.

Pros

  1. Portability: Applications in containers can run consistently across different systems and environments.

  2. Isolation: Containers provide a secure and isolated environment for application development, reducing the risk of conflicts and compatibility issues.

  3. Resource utilization: Containers provide a lightweight and efficient way to run applications, reducing the use of system resources.

  4. Scalability: Containers can be easily replicated and scaled to meet the demands of a growing application.

  5. Reproducibility: Containers allow for consistent and repeatable development and deployment processes, reducing the risk of human error.

Cons

  1. Complexity: The use of containers can introduce a new layer of complexity to the development and deployment process.

  2. Security: Containers can pose security risks if not properly configured and maintained.

  3. Resource utilization: While containers can be efficient with resources, they can also consume significant resources when running multiple containers on a single host.

  4. Integration: Integrating containers with existing systems and processes can be challenging, requiring significant technical expertise and resources.

  5. Cost: The deployment and management of containers can be more expensive than traditional deployment methods, due to the need for additional hardware and software resources.

Conclusion

Developing inside a container, especially using VSCode devcontainers, provides a number of benefits for software development. Containers offer portability, isolation, resource utilization, scalability, and reproducibility, making it easier to manage the development environment and reducing the risk of compatibility issues. However, there are also some challenges associated with containers, such as complexity, security, resource utilization, integration, and cost. By following the steps outlined above, developers can quickly and easily get started with VSCode devcontainers and experience the benefits of containerized development for themselves. Whether you are developing a new application or migrating an existing one, containers can help streamline your development workflows, improve your productivity, and increase the quality of your code.
We'll look deeper into the abyss in the future, to stay updated follow me on Twitter at AzanulZ or connect with me on Azanul Haque.

Did you find this article valuable?

Support Azanul Haque by becoming a sponsor. Any amount is appreciated!