Developing before and after Docker

3 minute read

Before Docker

When I started my carrer as a software developer in 2009 and I had to develop an application I needed to install all the services before starting to write a single line of code. It means installing mysql in my computer, installing JBoss, Tomcat or whatever application server needed for the software.

Configurations out of control

That was a waste of time because - and a source of problems - i.e: exact version of application server, exact version of jvm with the same configuration to start, installing certificates to have SSL, configurations in the standalone.xml of JBoss …

What happened if the server configurations are different depending on the environment? (dev, integration, staging, production).

Before docker you were deploying only the ear to an application server that its configuration was out of your control. That would mean that your app maybe didn’t behave the same way in the different environments, so if you had tested your app in your computer or in a integration environment it was possible that you would get different results.

After Docker

Docker automates the deployment of applications within software containers, providing an additional layer of abstraction and automation of application virtualization on multiple operating systems.

With Docker you are deploying not only an ear, you are deploying a container that has an operating system, the application server configured and the ear with the code that you have written.

With Docker you clone a repository from your code repository and you just need to create the docker image and run docker compose up if a docker-compose.yml file exists in the repository.

Docker compose

Docker Compose is a tool for defining, running, and managing multi-container Docker applications. Services are defined in a configuration file (a YAML format) and can be created and run all together with a single command.

See below an example of docker-compose.yml

version: '3'
services:
  my-micro-service:
    image: my-micro-service
    container_name: "my-micro-service"
    ports:
      - "8080:8080"
      - "8787:8787"
    volumes:
    - ./log/:/opt/jboss/jboss-eap-6.4/standalone/log
    environment:
      - ENVIRONMENT_VARIABLE=environment_value

This command creates you all necessary to run your app locally and start your development. If you need kafka you can run it adding in the docker-compose.yml, if you need an elasticsearch you can do it also, if you need neo4j or mysql you can add it too.

There’s no need to install all this manually in your computer. This saves a lot of time to you as a developer, and if your team where you are working is big enough you can save a lot of time and money to your company.

Resources separated by environment

All the properties and files that you need to configure your application should be inside your repository. The different datasource configuration files should be in the different folders according to each environment.

In a Java application, you would have a folder for each environment with the properties and other resources that you need to have in each environment.

I.e: You would have a datasource file for dev which points to the development database, you would have a datasource for integration environment pointing to a database that is a copy of production and you would have a datasource pointing to a production database.

A code repository has to be the source of truth of your application, everything should be inside it to be able to run it like you were in production.

Vault to store secrets

One thing that should be taken into account is that secrets should not be inside your repository. You should use something like vault to store secrets and connect to this service to retrieve those secrets when are needed and not storing them in the repository.

Conclusion

Life is easier for developers now with Docker because we don’t have to dedicate time to install all the services that your app is using and we can start developing much faster.

Also, having everything in the repository helps reducing errors because you have all the configurations that your application needs to work.

In the links below you can find more info if you are interested in Dockerize your Java application.

  • https://www.atlassian.com/blog/software-teams/deploy-java-apps-with-docker-awesome
  • https://www.oreilly.com/ideas/how-to-manage-docker-containers-in-kubernetes-with-java
I won't give your address to anyone else, won't send you any spam, and you can unsubscribe at any time.
Disclaimer: Opinions are my own and not the views of my employer

Updated:

Comments