DEV Community

Cover image for AltSchool Of Engineering Tinyuka’24 Month 10 Week 1
Ikoh Sylva
Ikoh Sylva

Posted on

AltSchool Of Engineering Tinyuka’24 Month 10 Week 1

You can catch up on our previous session in case you missed it here! Following that, we will be diving into a little hands on project, solidifying what we learnt previously about IAC. Let’s dive in!

Image of a satalite dish

This project uses Terraform (a tool that automates infrastructure) to tell Docker (a tool that runs applications) to create and run:

  • A web server (Nginx)

  • A custom web application (your own simple website)

  • A private network connecting them

  • All created automatically with one command

So instead of manually:

  • Installing Docker images

  • Creating containers

  • Mapping ports

  • Building Dockerfiles

  • Managing networks

…Terraform does all of it for you.

You write your instructions once, then Terraform builds everything from scratch in seconds.

It’s like writing a recipe once, and Terraform becomes the chef that prepares the meal anytime you ask.

Why This Project Is Perfect for a Beginner

1. You learn real DevOps tools (Terraform + Docker) with simple concepts

You get to use two of the most in-demand tools in cloud engineering:

  • Docker → Makes applications portable

  • Terraform → Automates infrastructure everywhere (AWS, Azure, GCP, etc.)

This project teaches you both, without overwhelming complexity.

2. You’ll see how “Infrastructure as Code” works instantly

Traditionally, engineers would install everything manually.

Now, professionals use IaC tools like Terraform to automate everything.

This project will show you how IaC works by letting you:

  • Describe your setup in code

  • Build everything with terraform apply

  • Destroy it cleanly with terraform destroy

It’s a simple but powerful introduction to automation.

3. It will build your confidence i.e you deploy a real app

Even though this is a beginner project, you’re not doing something fake.

You are actually deploying:

  • A working web server

  • A working custom website

  • A functioning network

  • Infrastructure created entirely by code

That’s a huge confidence boost for someone just starting out.

4. You’ll learn concepts that apply to all cloud platforms

This project teaches foundational skills used in:

  • AWS ECS/EKS

  • GCP Cloud Run

  • Azure Container Instances

  • Kubernetes clusters

  • CI/CD automation

  • DevOps pipelines

If you understand this project, you’re already ahead in cloud engineering.

5. It’s safe everything happens on your computer

No cloud account required.
No cost.
No risk.

This makes it perfect for beginners who want to practice real DevOps skills without paying for cloud services.

6. You’ll learn how apps are actually deployed in real companies

The workflow you’ll practice is how real teams deploy apps today:

  1. Write infrastructure code
  2. Build application containers
  3. Deploy automatically
  4. Tear down when no longer needed

This project is a small version of real production pipelines.

Deploying a Dockerized Web App Using Terraform (Local Infrastructure-as-Code Project)

Project Goal

You will use Terraform to automatically provision:

  1. A local Docker network
  2. A Docker container running Nginx
  3. Optional: a custom Docker image running a simple website

By the end, you will understand:

  • How Terraform manages Docker like a cloud provider

  • How Infrastructure-as-Code (IaC) automates container deployment

  • How to structure a real IaC project with best practices

Think of this project like giving written instructions (using Terraform) to a robot (Docker) that builds things for you.

You write the instructions once → Terraform reads them → Terraform tells Docker what to create.

These instructions create:

  1. A private space where your app will run (a network)
  2. The app engine (Docker image)
  3. The running app (container)

Let’s break down every part of the code in very simple English.

1. Terraform Setup Block

terraform {
  required_providers {
    docker = {
      source  = "kreuzwerker/docker"
      version = "~> 3.0.1"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

What this means in real life:

  • You’re telling Terraform:

"I want you to work with Docker. Here’s the plugin you need to do that."

  • Terraform uses “providers” just like a phone installs apps.

This line says:

"Install the Docker provider app so you can talk to Docker.”

2. Docker Provider Block

provider "docker" {}

Simple Explanation:

This tells Terraform:

"I will be using Docker installed on my computer. Be ready to talk to it."

There are no settings here because Docker is running locally and Terraform automatically knows where to find it.

3. Create a Docker Network

resource "docker_network" "my_network" {
  name = "webapp_network"
}
Enter fullscreen mode Exit fullscreen mode

Plain-English Meaning:

This creates a private digital neighborhood for your web app.

  • Think of a network like a street where your app lives.

  • It keeps things organized.

  • Apps inside the same network can talk to each other privately.

Image of a satalite dish

4. Download the Nginx Image

resource "docker_image" "nginx_image" {
  name = "nginx:latest"
  keep_locally = false
}
Enter fullscreen mode Exit fullscreen mode

Simple Explanation:

A Docker image is like a template or blueprint for creating applications.

Here, you're telling Terraform:

"Go to the internet and download the latest version of Nginx."

  • Nginx is a web server like a program that shows web pages.

  • keep_locally = false means:

"If I destroy this project later, you may delete the downloaded file."

5. Create the Nginx Container

resource "docker_container" "nginx_container" {
  name  = "nginx_web"
  image = docker_image.nginx_image.latest
  networks_advanced {
    name = docker_network.my_network.name
  }
  ports {
    internal = 80
    external = 8080
  }
}
Enter fullscreen mode Exit fullscreen mode

This is the heart of the project.

A container is like starting the engine built from the blueprint (image).

What each line means:

name = "nginx_web"

You're giving the container a friendly name.

image = docker_image.nginx_image.latest

You're saying:

"Create this container using the Nginx image you downloaded earlier."

networks_advanced { ... }

This attaches the container to the network you created.

It’s like saying:

"Put this app inside the same digital neighborhood you built earlier."

ports { internal = 80, external = 8080 }

This is very important.

  • Inside the container, Nginx always runs on port 80.
    (Think of this like the app’s room number.)

  • But your computer may have port 80 already used.

  • So you're saying:

"Show whatever is in the container’s port 80 on my computer’s port 8080."

So when you open:

👉 http://localhost:8080

You’re visiting the Nginx server inside the container.

OPTIONAL PART (Custom Web App)

If you added the custom website folder, these blocks apply.
If not, you can skip this.

6. Build Your Own Web App Image

resource "docker_image" "custom_web" {
  name = "terraform-web:1.0"
  build {
    context = "${path.module}/site"
  }
}
Enter fullscreen mode Exit fullscreen mode

Simple Explanation:

This tells Terraform:
"Go to the folder named /site, use the Dockerfile there, and build a custom web app image."

Think of this as:
You’re baking your own cake from scratch instead of buying one already made.

7. Run the Custom Web Container

resource "docker_container" "custom_web_container" {
  name  = "terraform_custom_web"
  image = docker_image.custom_web.name
  networks_advanced {
    name = docker_network.my_network.name
  }
  ports {
    internal = 80
    external = 9090
  }
}
Enter fullscreen mode Exit fullscreen mode

Meaning:

  • Start the custom-made image as a running web app

  • Put it in the same digital neighborhood

  • Make it accessible at http://localhost:9090

So the first Nginx container was:

👉 localhost:8080

Your custom web app becomes:

👉 localhost:9090

8. Initialize Terraform

terraform init

Simple Explanation:

This means:
"Terraform, please prepare yourself by downloading any plugins you need.”

Like installing apps before you can use them.

9. Create Everything

terraform apply

Terraform:

  • Reads your instructions

  • Shows you what it plans to create

  • Builds everything once you say "yes"

It automatically:

  • Downloads images

  • Creates containers

  • Creates network

  • Runs everything

10. Clean Everything Up

terraform destroy

This is Terraform’s way of saying:
"Undo everything I created and put things back to the way they were."

It deletes:

  • Containers

  • Images (if you want)

  • Network

Image of a satalite rader

This project teaches beginners how to automate the deployment of real applications using Terraform and Docker giving them hands-on experience with modern DevOps and cloud engineering practices.

I encourage you to dive deeper into the concepts we've discussed and continue practicing to refine your skills. If you have read all the way to this point thank you So much! I appreciate the effort.

I’m Ikoh Sylva, a passionate cloud computing enthusiast with hands-on experience in AWS. I’m documenting my cloud journey from a beginner’s perspective, aiming to inspire others along the way.

If you find my content helpful, please like and follow my posts, and consider sharing this article with anyone starting their own cloud journey.

Let’s connect on social media. I’d love to engage and exchange ideas with you!

LinkedIn Facebook X

Top comments (0)