Containersare taking the lead on the virtual machines, as it makes installation quicker and easier, it runsfaster and it takes less space on your computer. To understand the technological reasons behind this, read this great article.
If you’re using an old app deployed using VMs, here is a way to migrate to a containerized app with Docker and docker-compose.
Then make sure you are able to run it completely on your laptop « the old way ». It helps you find non-authenticated routes you can easily call to test, understand the db provisioning which is done, etc.Take this opportunity to measure the installation time to check the difference with your new docker environnement ;)
For each part answer these questions to list the steps you will need in your Dockerfile:
Which process starts the app? For example for a node app it could be node ./server.js
. Which files need to be inside the docker during the runtime?
Do base images already exist in docker hub? Are they maintained? If yes, are an “alpine” version, usually the lighter one, available?
Which environment variables are set? You should look for .env
file.
Build each Dockerfile. Start with the FROM
instruction, then COPY
the necessary files, declare the environment variables with the ENV
instruction. RUN
the necessary commands to build the binary file and use the CMD
instruction to be sure it will be executed. Remember, one container equals to one process.Then test each part individually by running docker build -t <IMAGE_TAG>
and then docker run -p <HOST_PORT>:<CONTAINER_PORT> <IMAGE_TAG
>
When you’re containerizing your application, it’s easy to separate the reverse proxy, the app and the database, and it often tempting to do more by turning your monolithic app into microservices. Nevertheless it’s not always a good idea as it can turn the containerization into a big thing. First containerize your monolithic app, then you will be able to improve it and create easily microservices one after the other.
Later on you could even transform each services into Kubernetes resources to have an iso software factory!