Skip to content

shreya-mishra325/docker-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐳 Docker API

A simple Node.js + Express backend containerized using Docker.
This project was built as my first hands-on experience with Docker, where I explored how to containerize a backend service, manage environment variables, and run applications inside containers.


🛠 Tech Stack

  • Backend: Node.js, Express.js
  • Containerization: Docker
  • Environment: WSL (Ubuntu)
  • Config: dotenv

🚀 Features

  • Simple REST API using Express
  • Dockerized backend application
  • Environment variable support using .env
  • Runs in background using containers
  • Easy container lifecycle management

🌐 API Endpoints

Method Endpoint Description
GET / Returns status message
GET /api Returns JSON response

⚙️ Setup & Usage

1️⃣ Clone the repository

git clone https://github.com/shreya-mishra325/docker-api
cd docker-api

2️⃣ Run locally (without Docker)

npm install
npm start

3️⃣ Run with Docker

Build Docker image

docker build -t docker-api .

Run container

docker run -d -p 5000:5000 --env-file .env --name docker-api-container docker-api

4️⃣ Verify container

docker ps

5️⃣ View logs

docker logs docker-api-container

6️⃣ Stop container

docker stop docker-api-container

7️⃣ Restart container

docker start docker-api-container

🌍 Access API

http://localhost:5000
http://localhost:5000/api

⚠️ Challenges Faced

  • Docker Desktop was consuming a lot of memory and frequently got stuck on "Starting Docker Engine"
  • Even after multiple restarts, it didn’t work properly
  • Had to uninstall Docker Desktop completely

👉 Final approach:
Switched to Docker inside WSL (Ubuntu), which was much lighter and worked reliably


Other Issues

  • .env file not found → commands were run from wrong directory

  • .env not visible → learned hidden files require ls -a

  • Container name conflicts → removed existing containers before running new ones

  • Multiple unused containers → cleaned using:

    docker rm -f $(docker ps -aq)


💡 Key Learnings

  • Difference between Docker image and container
  • How to containerize a backend service
  • Using .env inside Docker
  • Running containers in background
  • Debugging Docker issues in real scenarios
  • Using Docker efficiently via WSL instead of Docker Desktop

About

A simple Node.js API containerized using Docker. Built to learn and explore containerization concepts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors