How to Deploy Your First Docker Container (The Right Way)
Learn the essential steps and best practices to deploy your first Docker container easily and efficiently, even if you’re new to containerization.

If you're just getting started with Docker and feel overwhelmed by the CLI commands, Dockerfiles, and networking jargon — you're not alone.
This guide is here to walk you through deploying your very first Docker container the right way, with clarity, best practices, and zero fluff.
By the end of this article, you’ll have:
- Pulled and run a Docker image
- Created your own Docker container from a simple app
- Learned essential Docker commands
- Avoided common beginner mistakes
Let’s dive in.
🐳 What is Docker (In Simple Terms)?
Docker lets you package your application with everything it needs (code, libraries, dependencies) into a container that can run reliably anywhere.
It’s like putting your app in a sealed box. Whether it's a Mac, Windows, or Linux machine — it will run exactly the same.
🔧 Prerequisites
Before we begin, make sure you have the following:
- ✅ Docker installed
- ✅ A terminal or command line interface (PowerShell, Terminal, etc.)
- ✅ Basic familiarity with shell commands
- ✅ (Optional) A Docker Hub account if you want to push images
✅ Step 1: Test Docker is Installed
Open your terminal and run:
docker --version
If installed correctly, you’ll see something like:
Docker version 24.0.5, build ce6d9f1
Then, test Docker with:
docker run hello-world
This will pull a test image from Docker Hub and display a success message.
🌐 Step 2: Run a Real Container (Nginx)
Let’s try running a real app — Nginx, a popular web server.
docker pull nginx
docker run -d -p 8080:80 nginx
🔍 What does this mean?
-d
: Detached mode (runs in background)-p 8080:80
: Maps your host’s port 8080 to the container’s port 80nginx
: The name of the image
Open a browser and visit: http://localhost:8080
You should see the Welcome to Nginx page.
🛠️ Step 3: Create Your Own Docker Container
Now let’s Dockerize a simple Node.js app.
🗂 1. Create a project folder:
mkdir my-first-docker-app
cd my-first-docker-app
📄 2. Add app.js
:
// app.js
const http = require('http');
const PORT = 3000;
http.createServer((req, res) => {
res.end("Hello from Docker!");
}).listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
📄 3. Add package.json
:
{
"name": "docker-app",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
}
}
Run npm install
to generate the node_modules
.
📦 Step 4: Write the Dockerfile
Create a DockerFile
in the root;
# Use an official Node.js image
FROM node:18
# Set working directory
WORKDIR /app
# Copy app files
COPY . .
# Install dependencies
RUN npm install
# Expose port
EXPOSE 3000
# Start app
CMD ["npm", "start"]
🚀 Step 5: Build & Run Your App
🧱 Build the Docker image:
docker build -t my-first-app .
▶️ Run the container:
docker run -p 3000:3000 my-first-app
Visit http://localhost:3000
You should see: Hello from Docker!
⚙️ Bonus: Useful Docker Commands
Command | Description |
---|---|
docker ps | See running containers |
docker stop <container-id> | Stop a running container |
docker rm <container-id> | Remove a container |
docker images | List available images |
docker rmi <image-id> | Remove an image |
docker logs <container-id> | View logs from a container |
⚠️ Common Beginner Mistakes
- ❌ Forgetting to map ports: Your app runs, but you can’t access it.
- ❌ Using
latest
tag carelessly: Use specific versions when possible. - ❌ Not cleaning up old containers: Use
docker system prune
. - ❌ Skipping
.dockerignore
file: You end up copyingnode_modules
unnecessarily.
Create a .dockerignore
:
node_modules
npm-debug.log
✅ Best Practices
- ✅ Keep Dockerfiles clean and simple
- ✅ Use smaller base images (like
node:18-alpine
) - ✅ Tag images explicitly (
my-app:v1.0
) - ✅ Push to Docker Hub if needed
💡 Done with Docker?
If you're finished experimenting and want to remove Docker cleanly from your system — with no containers, images, networks, or leftover services —
➡ Check out: How to Properly Remove Docker
🎯 Final Thoughts
Congratulations! You’ve just deployed your first Docker container — the right way. You now understand the basics of:
- Pulling and running Docker images
- Writing Dockerfiles
- Building and deploying your own containerized app
Next up, you might want to explore:
- Docker Compose for multi-container apps
- Volume mounting for local development
- Pushing images to Docker Hub