Suppose Something is Dockerizing but It’s Not The Shield Hero Season 2
Festivities Abound
December 31st, New Year's Eve. You never had good memories from your childhood of this date. You've always spent every year alone, watching videos of other people celebrating while you take refuge from the ear-piercing fireworks and hit the bed after Cinderella had lost her magic. Normally you would worry of what to say to your relatives over another year of unemployment, but you couldn't care less about them now.
"Hm? Isn't this place..." You murmur before continuing forward. Your team decided to hold a New Year's party at a pub in the shopping district. Alex insisted that it's the best place to get a drink in town, but now that you're here you think you can figure out his intentions. You walk around until you stumble upon 3 familiar faces.
"Yo, why the long face?" Alex prods you, looking drunk already. Your intuition is spot on as you see Maya sitting beside Alex, calming him down. "Nothing, I never really celebrated New Year's before, so I was just reminiscing a little bit." You reply as you sit down next to Riley. Emory had also been invited, but they declined citing they have stuff to do. Apparently Emory never attended one of these because of "things to do". You order some tea and converse in small talk, mostly dominated by Alex's rambles.
"You know, you don't really talk about yourself. Emory too. Where were you before all this?" inquires Maya. The focus suddenly shifts. You feel a slight shortness of breath before calming yourself with another sip. There's not much you can say. Emory has told you to come up with a believable narrative, but you come up empty. "Oh, well... I've just been out of work for a while now and I would hate to work in retail. Mostly stayed at my place since I don't have relatives nearby."
You feel like telling your true past shouldn't be a problem, as long as you didn't mention about being from another world and all. Alex and Maya gave you a warm smile, but Riley seems to have raised an eyebrow. "You're not in debt or anything, right? It must be hard to survive in this city without a job and family." They say.
You never considered that surviving without financial support in a big city would be that weird, but you didn't account that your parents has always given you some amount at least until you find a job. "Ah yeah, I had a large saving I got from my parents." You casually mention the fact. It is the truth back in your world, and from what you gather, culture here doesn't seem too different. But little did you know that you've just opened pandora's box.
"So you're not from here? Where are you from then? I'm from Praston myself. Getting all the paperwork done to move here was a chore and a half ins't it?" Maya pressed on. At this point you realized that you might have ran your mouth a little bit too much. "Of course that's going to be the next question!" You thought to yourself. Where even is Praston?
Years of social gathering should've prepared you to navigate through minefields like this, but you've barely attended any in the past world, let alone here. Maybe this is the reason Emory doesn't participate in gatherings. You start to scramble for a good answer.
"Oh, the government had this program, and uhh... I applied for it and-"
Ring Ring Ring
Your phone rings. You set your ringtones to silent except for one person, Emory, in case any emergency happened. It's as if they had been watching from the start. The grace of an angel bailing you out of a bad situation...
"Sorry to do this to you, but can you come to the office?"
...into a worse one.
A Not So Happy Carol
You arrived at the dark and desolate office. While normally there are several security personnels, only a few still remained. It's holiday, naturally everyone wants to be with their loved one. You told the others back at the pub that it's an emergency situation and left in a hurry. While you feel bad, this gives you more time to get your story straight and maybe a chance to consult Emory.
As you walk, you began to wonder what's up. Emory never asks for other's help, but why are they working in the first place? You had thought that they're a hard worker, but not to this point. Though you feel happy that Emory would rely on you for once. Your mind starts humouring the idea of them seeing you in a different light, as you have always seen a different side of them recently.
You rushed over to your department and see a familiar yet disheveled face. "How long have you been here?" You asked gently, as if to signal a change of pace. "That doesn't matter. Sorry to intrude on your break. It was supposed to be something I could handle myself, but something came up" Emory grunted. "There are actually two systems that I need to work on, normally I would press on however long it will take..." Emory then paused as if considering something, perhaps the right words?
"But, maybe just this once I would like to also be done in a timely fashion. And I figured a certain someone owes me more than a little bit." They continued.
You start to feel bad, but felt that behind the remark Emory finally found the will to rely on someone. As usual though, they said that with a straight face. So who knows what Emory is really thinking about.
"Of course. I'd be more than happy to be of service. What is the problem?" You asked, Emory did help you get out of a bad situation, albeit indirectly.
"Right, let's get started"
Docker
"So how did you ended up with spending your holiday here?"
You had been wondering what is Emory's motive here. Being in the office outside work hours and above all, during a holiday, was something you can't imagine, even for Emory. There should be a specific reason.
Howver,Emory didn't budge at all and kept on typing. It lasted for a minute or two before Emory decided to give the reply you wanted. Emory gazed at you. But, in the last second Emory decided to change their mind and ignore the question. As if Emory was trying to hide something.
"So what we want to do here is to Dockerize the application we have developed. Is it correct?"
You decided to change the topic after seeing Emory's reluctant reaction to the question, respecting their privacy.
"Yes" Emory replied. Their voice sounded a bit trembling. Maybe the tension from hesitation whether to tell you the truth or not. Then, for a split seconds they looked at you before commented, "I assume you remember what happened with the last application."
"Yeah. There is no way I can forget about it."
Yes. There is no way anyone in the team able to forget it. When your team thought everything is over after the development and the deployment, fate didn't smile at you. Everything was going well in the staging server. More or less, the behaviour in the staging was the same with what you saw in the local environment. But, somehow production server didn't want to see the relief on your team's face and the application failed to deploy miserably. Alex had suspected the root problem was because of multiple java and external other dependencies existed in the server. The management saw the sleepless nights Alex must have endured to make sure the application still deployed on time and they asked for a change in the workflow.
"We will soon need to release the next phase of that application. So we need to do something so the same problem won't happen again. Alex and I proposed that we need to use container in the next deployment. With the use of container we can make the application's enviroment even more isolated with each other. We can even mimic the production server better with container, to comply with Dev/Prod parity factor. "
Emory explained the supposedly technical stuff with a much more neutral tone. You were also relieved that the first question did not bother them that much. But, you also realized. Why did Emory choose to work on that now? In the middle of new year's eve? They could have just done it after the holiday session. Yes, there was no rule from the kingdom that forbids this kind of work behaviour but it's just so unthinkable that some will do it for real. For what purpose? That question raised in your head for some seconds before you answered it yourself. To give the team a bit of rest time in the new year.
Emory then suddenly murmured something. The look on their face changed. The voice was so soft to hear but you could judge what it is. Emory might had seen your face when you realized the intention.
"I just wanted to repay the debt when I was sick. So..." The voice was getting louder, enough for you to hear. You had expected that sort of response. But the situation was becoming more awkward each second and you decided to get over with it.
"I will start to dockerize the backend application. " You tried to avoid a more tactless conversation with working as the alibi.
Dockerizing The Application
"I assume you are bit familiar with Dockerfile
"
"Yes. It's a file with the instruction to build and run the containerized application, isn't it? I have created some when I had Alex to taught me. However, I don't have any experience in dockerizing a more complex application. I believe there is a need for the containers to communicate with another container in this system. "
"Yes." Emory approved your observation. "As you can see we have two Springboot applications here: the trade system and company system. Basically, you can see that the trade system dependent on the company system. On top of that both applications also need their own instance of PostgreSQL database. So basically you need to run four docker images for the backend application. "
"So if I not mistaken, I need to run both instance of the PostgreSQL containers for both application first, then run company system container, and last the trade system. "
"Correct. "
"But how can we make the container communicate with each other? I am sure that database host and service url are not pointing to localhost
anymore. "
"It is pointing to the host of the target container. So it will be the name of the target container. You will need to comply to configuration factor of the 12App to make this possible. "
"In short, we will use environment variables to pass the name of the said container?"
"Yes. One more thing you need to be aware is a container can only access another container if they belong to the same network. "
"Okay. Thank you Emory."
The information provided by Emory was enough to start to work on.
The first step of course to create a Dockerfile
for both application: CompanySystem
and TradeRouteSystem
.
This application structure is a Gradle multi-module consisting two Spring Boot app.
You need to define the Dockerfile
in each module.
Spring Boot with Docker is a good article to start with.
However you need to make some adjustment, e.g. JDK base image.
Create the image for both of the application using docker build.
You can define a network via docker network create
.
A full docs can be found here.
Once done, you can try to create the container instance of the related images using docker container command.
You will need to create the container and start it using the above command.
A container can have some environment variables defined.
You need to utilize these variables to run the container.
An official image such as PostgreSQL has a set of variables defined in their Docker Hub page.
Meanwhile for CompanySystem
and TradeRouteSystem
you can read all set of variables in the README of the repository.
The Clock Strikes 12
You entered the last line of code and pushed the result to the repository, everything seems to check out. You look at the clock and it shows 11:50. The same old memory every year, spending New Year's in a dimly lit room in front a computer. Only this time, you're accompanied by someone else.
"Hm?" You noticed something at the corner of your eye, a figure. A few, actually. And they're not Emory. You have heard of ghost stories on the office before, though you're not the believer type. Suddenly, one of the figure draws closer. You feel chills and prepare for...
"What? You looked like you've just seen a ghost." The figure spoke, but you know this voice. A voice of someone who shouldn't have been here. "Is something wrong?" another figure tapped your shoulder. You cleared your eyes and confirm both source of voices.
"Alex? Riley? What are you guys doing here? Weren't you going to celebrate New Year at the town's square?" You asked in confusion. "Well, we did before someone decided to ditch. Can't you be more grateful? Geez." Alex sneered, he looks pretty pissed.
Now that you look again, a few other computers in the office are turned on. It seems that they also did some work. "Did Emory ask you two?" You inquired. "Ya think? Obviously not. Honestly, we're pretty stumped that Emory asked you. Voodoo magic I tell ya." Alex went on, his speech pattern is a bit weird. Maybe he's still drunk.
"But then-" Before you could respond, Riley interjected. "It's our decision. We can tell from your call that you're going here to help Emory. There's no way we could be partying while knowing that. We're a team."
You did feel like your task went significantly faster in the middle, it must've been because of these two. You feel guilty, but at the same time happy and relieved. The fact that they're here means Emory didn't turn their help down.
You reported to Emory. They didn't mention anything about Alex and Riley, presuming that you had talked to both anyways. "For the record, it would be weird to ask them not to help after I asked for your help." While the tone is the same, you can sense a small sense of embarassment.
You returned to your desk and turned off your computer. Alex and Riley sat on a sofa near a window. You followed them and sat down. Emory walked in with four cups of coffee. Each of you took one without saying a word, everything was silent. You felt like nothing needs to be said, but to bask in the sense of camaraderie.
The clock striked 12. Fireworks started to fire outside, must've been from the Town's Square. The four of you did a little toast and took a sip. It's sweet, perfect for such a good night.
Maybe you can tell Alex and Riley after all, though you wouldn't know how Emory will response if you say that out loud. Why can't you tell people about being from another world anyway? Though you suppose the fear should be enough to keep you from something stupid. Trust is a fickle thing, but surely you'll figure it out.
"Happy new years!" everyone shouted. You're sure that today will be a memory you will recall for years to come.
Checklist
- Create
Dockerfile
for bothTradeRouteSystem
andCompanySystem
. - Create a network for your system
- Create two containers of PostgreSQL that use the network you just created.
- Create containers for both applications. Make sure you can access it via browser (your
localhost
). Make sure it has the same behavior as yourpractice-6
application.
Bonus
You can attempt the following bonus tasks:
Dockerhub
- Create a Docker Hub account
- Push your image to Docker Hub
Docker Compose
There is a way to automate and compose what you have done so far by using docker-compose
. It needs to be installed separately from Docker. Try to run the container using docker-compose
. Make sure it has the same correct behaviour as the container you had run before in the previous section. Please install docker-compose
first before doing this part. Please read more about how to use docker-compose
on your own.
Checklist
- Create
docker-compose.yml
in the rootpractice-7
folder - Make sure the application can run via
docker-compose up
Created: 2022-04-12 23:06:51