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?
- Consistency: Runs the same across all machines (development, test, production).
- Isolation: Applications run in separate containers without interfering.
- Portability: “Build once, run anywhere” approach.
- Efficiency: Lightweight compared to virtual machines.
- Scalability: Easy to scale up or down.
- 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
docker images: Lists all downloaded images.docker ps -a: Shows all containers (running and stopped).docker exec -it my-nginx bash: Opens an interactive terminal in a running container.docker logs my-nginx: Shows logs from a container.docker build -t my-app .: Builds an image from a Dockerfile in current directory.docker rmi nginx: Removes an image.
Next Steps
- Learn about Dockerfiles to create custom images.
- Explore Docker Compose for multi-container applications.
- Study Docker volumes for persistent data storage.
- 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.
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.
Enjoying the content?
If this article helped you, you can support the author with a coffee. It keeps new posts coming.
Comments 0
No comments yet
Be the first to share your thoughts.