Table of contents
The Problem Before Docker
Before Docker came along, deploying and managing applications was quite a headache. Applications were typically deployed on physical servers, which not only cost a pretty penny but were also a pain to scale. Moreover, these applications often got into nasty conflicts with each other, making it tough to keep them isolated.
Specific Problems:
Cost: Running applications on physical servers meant shelling out big bucks for hardware and maintenance.
Scalability: Scaling up applications on these servers was a hassle. To expand, you had to buy more servers, adding to the costs.
Conflicts: Apps often get in each other's way on the same server, leading to performance problems and even crashes.
Isolation: Isolating apps from each other was a tough nut to crack. If one app had a security vulnerability, it could spell trouble for the others.
What is Docker?
Docker is like a superhero for this mess. It's a containerization platform that lets you package your apps into nifty, self-contained units called containers. These containers are a breeze to deploy and manage, and they stay out of each other's hair. No more app conflicts!
Containers are like virtual machines, but they're way lighter and more efficient. They share the underlying operating system kernel, but each container has its own little sandboxed world for files and processes. This means multiple apps can coexist peacefully on the same server without throwing punches.
Docker is also a rock star when it comes to developing and deploying microservices-based apps. Microservices are like tiny, independent services that team up to create a bigger app. With Docker, you can neatly package each microservice into its own container, making scaling and updates a walk in the park.
It's a hit in the world of continuous integration and continuous delivery (CI/CD) pipelines, too. These pipelines automate the process of building, testing, and deploying apps, and Docker can make it all happen quickly, reliably, and on repeat.
Aspect | Containers | Virtual Machines (VMs) |
Architecture | Share the host OS kernel, isolated user space | Run a full OS with a hypervisor on physical hardware |
Resource Utilization | Highly efficient, minimal overhead | Resource-intensive, significant overhead |
Isolation | Provides isolation at the user space level | Stronger isolation, as each VM has its own kernel |
Startup Time | Start quickly, often in seconds | Slower startup time, often in minutes |
Portability | Highly portable, can move between compatible hosts | Less portable due to larger size and hypervisor issues |
Maintenance | Easier to manage and update | More effort is required for maintenance, OS patching |
Use Cases | Ideal for microservices, CI/CD, lightweight apps | Suitable for strong isolation, legacy systems, diverse OS |
Why Docker is the Solution
Docker swoops in to save the day by letting you package applications into self-contained containers. These containers are super easy to deploy and manage, and they play nicely with each other. Here's the scoop on why Docker rocks:
Reduced Costs: Docker can save you some serious cash by cutting down on the number of physical servers you need.
Improved Scalability: Need to grow your apps? Just add more containers. It's that simple.
Less Conflicts: Docker keeps your apps in their own little bubbles, reducing the risk of them fighting like siblings.
Better Security: Isolated containers mean it's way harder for attackers to exploit vulnerabilities.
In a nutshell, Docker makes app deployment and management a breeze. It's budget-friendly, scales like a champ, keeps the peace, and beefs up your security.
What is Docker Engine?
Docker Engine is the real powerhouse behind the scenes. It's the open-source container orchestration platform that does all the heavy lifting. Think of it as the beating heart of Docker, responsible for creating, running, and dismantling containers.
What is Docker Desktop?
Docker Desktop is like the slick, user-friendly front end for Docker Engine. It's a commercial app that comes with a graphical user interface, a Docker daemon, a Docker CLI, and even a Docker Compose file editor. Perfect if you're new to Docker and want to dive in headfirst.
Comparison of Docker Engine and Docker Desktop
Feature | Docker Engine | Docker Desktop |
Open source | Yes | No |
Commercial | No | Yes |
Graphical user interface | No | Yes |
More powerful and flexible | Yes | No |
Easier to use | No | Yes |
Suitable for beginners | No | Yes |
Suitable for production | Yes | Yes |
Available on Linux | Yes | Yes |
Available on macOS | Yes | Yes |
Available on Windows | Yes | Yes |
Installation of Docker Engine on Fedora
To get Docker Engine up and running on Fedora, follow these simple steps:
Update your system:
sudo dnf update
Install the Docker Engine package:
sudo dnf install docker
Start the Docker service:
sudo systemctl start docker
Enable the Docker service to start at boot:
sudo systemctl enable docker
Add yourself to the docker group:
sudo usermod -aG docker $USER
Log out and log back in for the changes to take effect.
Installation of Docker Desktop on Fedora
Here's how to get Docker Desktop purring on Fedora:
Set up Docker's package repository by installing the dnf-plugins-core package (which provides the commands to manage your DNF repositories) and set up the repository.
sudo dnf -y install dnf-plugins-core sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
Download the Docker Desktop from the Docker website.
Open the rpm file and Install it.
Open Docker Desktop and follow the on-screen instructions to complete the installation.
To check the Docker Desktop installation and to run the "hello-world" image, run the below command:
docker run hello-world
You can pull other available images from Docker Hub.
Creating and Running a Demo Image with Commands in It
Ready to roll with a demo image? Let's do it!
Begin by setting up the necessary environment:
Create a test directory.
Move into this directory.
Create a file without any extension.
Edit the file and add the following to the file you've created:
# Use a lightweight base image FROM alpine:latest # Run a simple shell script that echoes "Hello, World!" CMD ["/bin/sh", "-c", "echo 'Hello, World!'"]
Build the image:
docker build -t my-hello-world -f sample .
In this command:
-t my-hello-world
specifies the name for the custom image.-f sample
indicates that the Dockerfile to use is named "sample."
You can also observe the created image in the Docker Desktop within the images section:
Run the image:
docker run my-hello-world
To stop the container, use this command:
docker stop <container>
To remove the container, fire this command:
docker rm <container>
Make sure to replace
<container>
with the actual container name when executing these commands.
Docker commands (Frequently used)
Command | Description |
docker pull <image> | Pull an image from a container registry |
docker images | List all locally available images |
docker run <image> | Run a container from an image |
docker ps | List running containers |
docker ps -a | List all containers, including stopped ones |
docker start <container> | Start a stopped container |
docker stop <container> | Stop a running container |
docker restart <container> | Restart a container |
docker rm <container> | Remove a stopped container |
docker rmi <image> | Remove an image |
docker exec -it <container> <cmd> | Execute a command in a running container |
docker logs <container> | View the logs of a container |
docker build -t <image> <path> | Build an image from a Dockerfile |
docker push <image> | Push an image to a container registry |
docker network ls | List Docker networks |
docker volume ls | List Docker volumes |
docker-compose up | Start services defined in a docker-compose.yml |
docker-compose down | Stop and remove containers defined in docker-compose.yml |
These are some of the fundamental Docker commands to help you manage containers and images effectively. You can run these commands in your terminal or command prompt. Be sure to replace <image>
and <container>
with the actual image or container names when using the commands.
Conclusion
Docker is like your Swiss Army knife for simplifying app deployment and management. It's beginner-friendly, but it can do some heavy lifting. If you want to make your life easier while juggling apps, Docker's worth a look.