100 days of Cloud: Day 5: Deploying my first ever API with Docker Compose - Adventures in Not Breaking Everything
Published: 2024-07-16 13:06:54

Alright folks, buckle up for another exciting day in the world of deploying a super cool (and totally not to brag, but incredibly useful) API! Today's agenda was all about using this nifty tool called Docker Compose. Now, full disclosure, going into this I wasn't entirely sure what I was getting myself into. Docker? Sure, I'd heard the name. But Docker Compose? Was that like a fancy way of writing music for otters? 

Thankfully, after some Googling that would make Sherlock Holmes proud (minus the deerstalker, because, well, Kenya is a bit warm for that), I figured it out. Here's the gist: imagine you have two essential parts to your application, like a peanut butter and jelly sandwich. You've got the peanut butter (my awesome API) and the jelly (a database to store all that good data). Docker Compose lets you package these two things up neatly and efficiently, ensuring they always play nicely together.  

**The Great Docker Compose Caper**

So, I whipped up a docker-compose.yml file, which is basically a recipe for how to put everything together. Here's what my code looked like:

```yaml
version: '3.1'
services:
  verisafe:
    image: verisafe:v4
    ports:
    - "8000:8000"
  postgres:
    image: postgres:latest
    environment:
      POSTGRES_USER: verisafe
      POSTGRES_PASSWORD: verisafe
      POSTGRES_DB: verisafe
    ports:
    - "5431:5432"
```

It took a bit of work, but hey, nothing worth having comes easy, right? Especially not when you're dealing with lines of code that look like they were written by a particularly enthusiastic alien overlord.    

After some tweaking (and maybe a few muttered curses under my breath), I ran the command to get everything up and running. And guess what? It worked!   Sort of.  

There were some hiccups, let's not sugarcoat it. My fancy API decided it wasn't too keen on talking to the database. Turns out, there was a bit of a communication breakdown.  Imagine trying to order a pizza when you and the delivery person speak entirely different languages - that was kind of the vibe.   

**AI to the Rescue (Kind Of)**

Here's where things got interesting.  I started poking around the internet, trying to decipher the error messages that looked like they were written in binary code.  Thankfully, with the help of some friendly online forums (and maybe a little nudge from a large language model that may or may not be me  ), I found the culprit: a missing environment variable.  

Apparently, my API needed the database's IP address to know where to find it. Oops!  ‍♀️  It was like trying to give directions to your friend's house without knowing the actual address -  a recipe for disaster (and a very hangry friend).

**Lessons Learned and What's Next**

So, what did I learn today? Well, a few things:

1. **Docker Compose is pretty darn cool.** It takes the complexity out of managing multiple containers and makes your life a whole lot easier.  Just remember to double-check those environment variables -  they're kind of like the secret sauce that makes everything work together.
2. **Error messages are not your enemy.**  They might be cryptic and confusing, but they're usually there to point you in the right direction.  Just be patient and persistent, and eventually you'll crack the code (pun intended).
3. **There's a large language model out there that may or may not be able to help you with your coding woes.**  Just sayin'.  

Tomorrow's adventure?  We're going to explore the wonderful world of CI/CD pipelines.  That's a fancy way of saying we're going to automate the process of building and deploying my API.  Wish me luck!  In the meantime, if you have any Docker Compose tips or tricks, feel free to share them in the comments below.  And hey, if you're ever feeling lost in the land of code, don't hesitate to reach out -  maybe together we can decipher those alien messages.