Tools
Tools: Docker & Docker Compose: From Zero to Server (A Practical Guide)
2026-01-22
0 views
admin
1. The Problem: "It Works on My Machine!" π« ## The Solution: The Digital Container π¦ ## 2. Preparation: Where Will We Work? π ## Step 1: Server Access ## 3. Professional Installation (All at Once) π οΈ ## 4. The Three Pillars of Docker: Image, Container, Registry ποΈ ## 5. Your First Container: Web Server in 5 Seconds π ## 6. How to Manage the Chaos? (Survival Commands) πΉοΈ ## 7. The Grand Finale: Docker Compose πΌ ## Step 1: Installation ## Step 2: Creating the Project ## Step 3: The Magic Begins ## 8. Why Did This Work "Right Away"? π ## Conclusion and Next Steps Welcome to the world of modern technology! If you're a beginner in programming or system administration, you've probably heard the word Docker constantly. It might sound complicated, but the truth is that Docker was created to make our lives easier, not harder. In this first part of our series, we'll journey from "What is this?" to launching an entire infrastructure with Docker Compose. And we'll do it the professional way β directly on a server. This article is a translation of the original Bulgarian article: Docker & Docker Compose: ΠΎΡ Π½ΡΠ»Π°ΡΠ° Π΄ΠΎ ΡΡΡΠ²ΡΡ Imagine you've written an amazing program. It works perfectly on your laptop. You send it to a client or upload it to a server and... boom! Nothing works. It turns out the server has a different version of Python, a library is missing, or the database settings are different. This is called an "environment conflict." Before Docker, programmers wasted hours (and days) configuring servers. Docker takes your program and encloses it in a "container." Inside this container is everything needed: When you give this container to someone else, it works in exactly the same way because the operating system on the computer no longer matters. Docker provides isolation. To learn Docker properly, you need to use it where it belongs β on a Linux server. Many tutorials start with Windows installation (Docker Desktop), but this often confuses beginners with additional BIOS settings, virtual machines, and unnecessary RAM consumption. That's why we'll take the professional approach. If you have your own server (VPS) with Ubuntu, great! If you don't, you can rent one for a few euros per month from providers like DigitalOcean, Hetzner, or local ones. Connect to your server via terminal (PowerShell on Windows or Terminal on Mac): Forget long guides. Docker provides an official script that does everything for you. Once you've logged into the server, simply copy and paste this: To check if everything is okay, type: If you see a version (e.g., Docker version 24.x.x), you're ready for the magic! β¨ Before we start something, you need to understand three basic concepts: Let's run Nginx β the most widely used web server in the world. On a regular server, its installation takes time and configuration. With Docker, it's one command: Command Breakdown (Important!): Result: Open your browser and type your server's IP address. You should see: "Welcome to nginx!". Congratulations, you're a system administrator! π Now that something is running, we need to know how to control it. (If something doesn't work, this is where you'll see why) One container is easy. But what do we do if we need a website (Nginx) + database (MySQL)? Writing two long docker run commands and manually connecting them is torture. This is where Docker Compose comes in. It allows you to describe your entire infrastructure in one file. On modern systems, it comes with Docker, but check with: Create a folder for your project and enter it: Now create a file named docker-compose.yml. You can use the nano editor: Put this code inside: (Press Ctrl+O, Enter, then Ctrl+X to save and exit nano) Instead of starting things one by one, just write this: What happened? Docker Compose read the file, understood you need two containers, created a virtual network between them, and started them simultaneously. Now you have a working web server on port 8080 and a database underneath it. To stop and delete everything at once: If you followed the steps, you probably already have a working system. Here are the secrets to success: Today you learned the basics of the most important technology for cloud services. You now know how to: In the next article, we'll move to the next level: How to package our own software. We'll write our first Dockerfile and turn simple code into a professional Docker image. About the Author:
Fedya Serafiev is the creator of ITpraktika.com β a platform dedicated to practical IT solutions and automation. With extensive experience in system optimization and web technologies, he transforms complex technical cases into clear and easy-to-follow steps. Original Article (Bulgarian): Docker & Docker Compose: ΠΎΡ Π½ΡΠ»Π°ΡΠ° Π΄ΠΎ ΡΡΡΠ²ΡΡ π If you found this article useful, consider supporting my work: π Your support means a lot! Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse COMMAND_BLOCK:
ssh root@your-ip-address Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
ssh root@your-ip-address COMMAND_BLOCK:
ssh root@your-ip-address COMMAND_BLOCK:
curl -fsSL https://get.docker.com -o install-docker.sh
sudo sh install-docker.sh Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
curl -fsSL https://get.docker.com -o install-docker.sh
sudo sh install-docker.sh COMMAND_BLOCK:
curl -fsSL https://get.docker.com -o install-docker.sh
sudo sh install-docker.sh COMMAND_BLOCK:
docker --version Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker --version COMMAND_BLOCK:
docker --version COMMAND_BLOCK:
docker run -d -p 80:80 --name my-site nginx Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker run -d -p 80:80 --name my-site nginx COMMAND_BLOCK:
docker run -d -p 80:80 --name my-site nginx COMMAND_BLOCK:
docker ps Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker ps -a Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker ps -a COMMAND_BLOCK:
docker ps -a COMMAND_BLOCK:
docker stop my-site Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker stop my-site COMMAND_BLOCK:
docker stop my-site COMMAND_BLOCK:
docker logs my-site Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker logs my-site COMMAND_BLOCK:
docker logs my-site COMMAND_BLOCK:
docker compose version Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker compose version COMMAND_BLOCK:
docker compose version CODE_BLOCK:
mkdir my-app && cd my-app Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
mkdir my-app && cd my-app CODE_BLOCK:
mkdir my-app && cd my-app CODE_BLOCK:
nano docker-compose.yml Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
nano docker-compose.yml CODE_BLOCK:
nano docker-compose.yml CODE_BLOCK:
version: '3.8' services: web: image: nginx ports: - "8080:80" database: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: your-password-here Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
version: '3.8' services: web: image: nginx ports: - "8080:80" database: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: your-password-here CODE_BLOCK:
version: '3.8' services: web: image: nginx ports: - "8080:80" database: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD: your-password-here COMMAND_BLOCK:
docker compose up -d Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker compose up -d COMMAND_BLOCK:
docker compose up -d COMMAND_BLOCK:
docker compose down Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
docker compose down COMMAND_BLOCK:
docker compose down - The code itself
- The libraries it uses
- System settings - You downloaded the installation script
- You executed it with administrator privileges
- Docker is now installed and ready to work - Image: This is a "frozen" snapshot of your program. It doesn't do anything, just sits on disk. Think of it as a cake recipe.
- Container: This is the actual cake. When you "start" the image, it becomes a live, working process (container). You can create 100 containers from the same image.
- Registry: The place where images are stored. The biggest is Docker Hub β it has ready-made images for everything: databases, web servers, programming languages. - docker run: Tells Docker to find the image and start it
- -d: (Detached) Means "run in the background." Without it, your terminal will be blocked by server logs
- -p 80:80: This is critical! The first 80 is your server's port. The second 80 is the port inside the container. We're saying: "When someone visits my IP, forward them to the container"
- --name my-site: We give it a name so we can recognize it
- nginx: The name of the image we're pulling from Docker Hub - See which containers are currently running: - See all containers (even stopped ones): - Stop the server: - See what's happening "inside" (Logs): - Clean server: When we work on clean Linux, there are no conflicts with Windows settings
- YAML syntax: Be careful with indentation in docker-compose.yml β it matters! Don't use Tab, only spaces
- Ports: If port 80 is occupied, you can always change it to 8081 or 8082 - Install Docker professionally
- Start ready-made programs (Images) as containers
- Orchestrate complex systems with Docker Compose - Docker Official Documentation
- Hetzner Cloud
how-totutorialguidedev.toaimllinuxubuntuserversystem administrationshellnetworkmysqlnginxdocker