Skip to content

Docker Guide: Introduction, Benefits, and Basic Example

Learn everything about Docker — from installation and setup to advanced containerization tips. Boost your DevOps skills with our comprehensive Docker guide for developers and system administrators.

Dasun Kalupahana 2 min read 718 views 0 comments

What is Docker?

Docker is an open-source platform that enables developers to package applications into containers — standardized, executable components that combine application source code with the operating system (OS) libraries and dependencies required to run that code in any environment.

Why Use Docker?

  1. Consistency: Runs the same across all machines (development, test, production).
  2. Isolation: Applications run in separate containers without interfering.
  3. Portability: “Build once, run anywhere” approach.
  4. Efficiency: Lightweight compared to virtual machines.
  5. Scalability: Easy to scale up or down.
  6. Rapid Deployment: Containers start almost instantly.

Basic Example: Running a Simple Web Server

Step 1: Install Docker

First, install Docker Desktop for your OS from docker.com.


Step 2: Verify Installation
docker --version

This shows the installed Docker version.

docker --version 
Docker version 27.5.1, build 9f9e405

Step 3: Pull an Image

Let’s use the official Nginx image:

docker pull nginx
  • docker pull: Command to download an image.
  • nginx: Name of the image (from Docker Hub).
docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
32e44235e1d5: Download complete
3b00567da964: Download complete
979e6233a40a: Download complete
1bc5dc8b475d: Download complete
d2a7ba8dbfee: Download complete
56b81cfa547d: Download complete 
Digest: sha256:6784fb0834aa7dbbe12e3d7471e69c290df3e6ba810dc38b34ae33d3c1c05f7d
Status: Downloaded newer image for nginx:latest

Step 4: Run a Container
docker run -d -p 8080:80 --name my-nginx nginx
  • docker run: Creates and starts a container.
  • -d: Runs in detached mode (background).
  • -p 8080:80: Maps host port 8080 to container port 80.
  • --name my-nginx: Names the container "my-nginx".
  • nginx: The image to use.

Step 5: Verify the Container is Running
docker ps

Shows running containers. You should see “my-nginx” listed.

docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                  NAMES
67994592401a   nginx     "/docker-entrypoint.…"   6 seconds ago   Up 5 seconds   0.0.0.0:8080->80/tcp   my-nginx

Step 6: Access the Web Server

Open a browser and go to http://localhost:8080. You should see the Nginx welcome page.


Step 7: Stop the Container
//container name 'my-nginx'
docker stop my-nginx

Stops the running container.


Step 8: Remove the Container
docker rm my-nginx

Removes the stopped container.

Key Docker Commands Explained

  1. docker images: Lists all downloaded images.
  2. docker ps -a: Shows all containers (running and stopped).
  3. docker exec -it my-nginx bash: Opens an interactive terminal in a running container.
  4. docker logs my-nginx: Shows logs from a container.
  5. docker build -t my-app .: Builds an image from a Dockerfile in current directory.
  6. docker rmi nginx: Removes an image.

Next Steps

  1. Learn about Dockerfiles to create custom images.
  2. Explore Docker Compose for multi-container applications.
  3. Study Docker volumes for persistent data storage.
  4. Investigate Docker networking for container communication.

If you found this helpful, feel free to share or drop a comment. Happy coding with Laravel! 🧱✨

Free resources for this topic

Get one practical tip every week

New tutorials, fixes and free cheat sheets from DEV Talk, straight to your inbox. No spam, unsubscribe in one click.

Free download: Docker cheat sheet (PDF)

Have a question about this post?

Ask the community: other developers and the author can answer.

Ask the community

Get notified about new articles

One click, no email needed. Turn it off anytime with the bell at the top.

Get new articles on your iPhone

Add DEV Talk to your Home Screen, open it, then tap the bell.

Rate this post
5.0
Share

Enjoying the content?

If this article helped you, you can support the author with a coffee. It keeps new posts coming.

Buy me a coffee (opens in a new tab)

Comments 0

Be kind. Comments with links are reviewed before they appear.

No comments yet

Be the first to share your thoughts.

Get new articles in your inbox

Practical tutorials and deep dives, about once a week. No spam, unsubscribe anytime.

Privacy policy

Add DEV Talk to your Home Screen

  1. 1 Tap the Share button in Safari's toolbar.
  2. 2 Scroll down and tap Add to Home Screen.
  3. 3 Tap Add. Open it from the Home Screen to read like an app and to turn on notifications with the bell.

We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.