Goal
Build one small setup that looks closer to a real project instead of a single isolated container example.
This page shows how the earlier Docker topics come together in one beginner-friendly project with an app service, a database service, shared configuration, and persistent storage.
Build one small setup that looks closer to a real project instead of a single isolated container example.
The project uses an app container and a database container working together through Compose and networking.
You see how Dockerfile, Compose, volumes, networking, and environment variables fit together in one flow.
project/
Dockerfile
compose.yaml
.env
package.json
server.js
const http = require("http");
const port = process.env.PORT || 3000;
const dbHost = process.env.DB_HOST || "db";
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end(`App is running. DB host is ${dbHost}`);
});
server.listen(port, () => {
console.log(`Server running on port ${port}`);
});
{
"name": "docker-small-project",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js"
}
}
FROM node:18
WORKDIR /app
COPY package.json /app
COPY server.js /app
EXPOSE 3000
CMD ["npm", "start"]
PORT=3000
DB_HOST=db
NODE_ENV=development
MYSQL_ROOT_PASSWORD=rootpass
services:
app:
build: .
ports:
- "${PORT}:3000"
environment:
PORT: ${PORT}
DB_HOST: ${DB_HOST}
NODE_ENV: ${NODE_ENV}
depends_on:
- db
db:
image: mysql:8
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
db.localhost instead of db inside the app container.depends_on means the database is fully ready.Next page: Lesson 9 focuses on Docker debugging and troubleshooting so you can fix common container problems with confidence.