My Docker Learning Journey: The Ups, Downs, and Fixing an Apache Issue

Rohit JangraRohit Jangra
4 min read

Introduction

Hey there! I recently embarked on a journey to learn Docker, and let me tell you—it’s been quite a ride. I've learned a ton from understanding Docker and troubleshooting real-world issues. I’m sharing my experiences here to help anyone starting, and I'm shouting out to Technical Guftgu on YouTube for being a fantastic learning resource.

So, What Exactly is Docker?

Docker is an awesome tool that lets you package your application and its dependencies into containers. Think of it as putting your app in a magic box that runs anywhere—whether on your laptop, your friend's computer, or a cloud server. No more "it works on my machine" problems!

Getting Docker Up and Running

Installing Docker was the first step, and it wasn’t too bad. Depending on your operating system, the process can differ, but Docker’s official docs make it simple:

  • Windows: Install Docker Desktop.

  • Mac: Same as Windows—Docker Desktop does the job.

  • Linux: Here, you’ll do a bit more, but it’s still straightforward.

Pro tip: After installation, run the command docker --version to ensure everything’s working.

The Good and the Not-So-Good About Docker

Why Docker is Awesome:

  • Consistency Everywhere: Your app behaves the same, whether it’s on a developer’s laptop or a cloud server.

  • Resource-Efficient: Containers share resources with the host, making them lighter than traditional virtual machines.

  • Scalability: It’s super easy to scale your app up and down as needed.

Where Docker Gets Tricky:

  • Steep Learning Curve: There’s much to learn, from basic commands to advanced concepts.

  • Security Concerns: Since containers share the host kernel, you must be cautious.

  • Handling Data: Figuring out data persistence and volumes can initially be confusing.

Diving into Docker's Core Components

Here’s a quick overview of what I’ve learned about Docker’s main pieces:

  • Docker Daemon: The "brain" running in the background, managing everything.

  • Docker Client: The command-line tool you use to communicate with the daemon.

  • Docker Host: The machine that runs the Docker daemon.

  • Docker Images and Containers: Images are the templates, while containers are the running instances.

My Go-To Docker Commands

These commands saved my life more than once:

  • docker run # Spin up a new container

  • docker ps # List active containers

  • docker stop # Halt a running container

  • docker rm # Delete a container

  • docker build # Create an image using a Dockerfile

Understanding Dockerfile: The Recipe for Containers

Think of a Dockerfile as a recipe that tells Docker how to build your container. It starts with a base image (like Ubuntu), then installs what you need:

RUN apt-get update && apt-get install -y nginx
COPY index.html /var/www/html
CMD ["nginx", "-g", "daemon off;"]

Keeping Data Safe: Docker Volumes

Containers are stateless by default, which means data disappears when the container stops. Docker volumes help you persist data across container restarts:

docker volume create my_volume
docker run -v my_volume:/data my_image

Making Your Containers Accessible: Exposing Ports

If you want your container’s service to be reachable from outside, you need to expose its ports. For example, to make a web app running on port 80 available:

docker run -p 80:80 my_image

Docker Hub: Your Image Repository

I also dove into Docker Hub, where you can pull images created by others or push your own. For example:

docker pull ubuntu  # Pull a basic Ubuntu image
docker push myusername/myapp:latest  # Push your custom image

Real-World Troubleshooting: Hosting a Website with Apache

Now, here’s where things got interesting. I set up an Apache server on an EC2 instance, and everything seemed fine… until I couldn’t access the site via its public IP. It was frustrating but also a valuable learning experience. Here’s how I solved it:

The Problem:
I started the Apache service, but the public IP wasn’t working. It turned out to be a security group issue in AWS.

The Fix:

  1. Update the Security Group:
    I went to the EC2 dashboard, selected the instance’s security group, and added an inbound rule:

    • Type: HTTP

    • Port: 80

    • Source: 0.0.0.0/0 (to allow all IP addresses)

  2. Restart Apache:
    I restarted the Apache service for good measure:

sudo systemctl restart apache2

Voila!
The website was now accessible through the public IP. It felt great to solve this one!

Final Thoughts

Learning Docker has been challenging but also rewarding. I've developed many practical skills and even fixed a few issues, like my Apache hosting problem. The Technical Guftgu channel was a fantastic resource that helped me understand Docker in simple terms.

If you renew to Docker, start with the basics. Don't worry about getting everything right at first. Troubleshooting and fixing issues are part of the learning process. Keep pushing those containers; soon enough, you will be a Docker pro!

0
Subscribe to my newsletter

Read articles from Rohit Jangra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rohit Jangra
Rohit Jangra