Note - This post is part 6 of a series on building a chat application in Go with ReactJS. You can find part 5 here - Part 5 - Improving the Frontend
In this part of the series, we are going to be focusing on adding Docker to our backend application.
Why are we doing this now you might ask? Well, before we look into things like authentication, load balancing and deployment, it’ll be good to have a standard way of deploying our application using containerization technology.
If this is your first time hearing about Docker and containerization technologies, then you may be questioning why we are using it?
For me, one of the main selling points is that it makes deployments so much easier. You are able to deploy your docker-based application to any server or platform that supports Docker.
This means that, regardless of where you are deploying to, you can start up your application with a single command.
Not only that, it eradicates the “it works on my machine” as, within your
Dockerfile, you dictate the exact environment that your application needs in order to start up.
The first thing you’ll need to do, is to install Docker for Desktop on your machine. This can be done here: Docker - Getting Started
Once you’ve installed docker and have it running locally, we can dive into creating our
Once we have defined our
Dockerfile, we can go ahead and build our Docker image using the
Note - If you are running on a slow internet connection, this next command can take a while to execute, however, subsequent commands will be a lot faster due to caching.
Upon successfully completing the
build step, we can then proceed to try running this like so:
As you can see, upon running this command and refreshing our client, we can see connections now coming in to our Docker-ized application and we can see the log files being printed to our terminal.
If we wanted to now go away and deploy this application to the likes of AWS, we’ve greatly simplified doing this. We can leverage something like AWS’ Elastic Container Service to deploy and run our container with just a few commands.
Conversely, if we wanted to use Google’s Cloud, we could deploy it to their container offering with no additional work needed! This just highlights one of the massive benefits of containerization for development.
No Docker for the Frontend?
At this point, you may be wondering why we aren’t doing the same for our
frontend/ application? The reason for this is that we are intending to deploy this frontend app to the likes of an AWS S3 bucket.
We don’t need anything fancy serving our frontend when we go to production, we just need something that will be able to reliably serve our built frontend files.
So, in this part of the series, we managed to add Docker to our backend application and how this benefits us, the developers when it comes to continuing development and deployments.
Enjoying This Series? - If you are enjoying this series, or have any feedback, I would love to hear it on twitter and see your progress in the form of screenshots! - @Elliot_f.