Docker Complete: All You Need To Know With Working

Docker Complete: All You Need To Know With Working

·

7 min read

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.

AspectContainersVirtual Machines (VMs)
ArchitectureShare the host OS kernel, isolated user spaceRun a full OS with a hypervisor on physical hardware
Resource UtilizationHighly efficient, minimal overheadResource-intensive, significant overhead
IsolationProvides isolation at the user space levelStronger isolation, as each VM has its own kernel
Startup TimeStart quickly, often in secondsSlower startup time, often in minutes
PortabilityHighly portable, can move between compatible hostsLess portable due to larger size and hypervisor issues
MaintenanceEasier to manage and updateMore effort is required for maintenance, OS patching
Use CasesIdeal for microservices, CI/CD, lightweight appsSuitable 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

FeatureDocker EngineDocker Desktop
Open sourceYesNo
CommercialNoYes
Graphical user interfaceNoYes
More powerful and flexibleYesNo
Easier to useNoYes
Suitable for beginnersNoYes
Suitable for productionYesYes
Available on LinuxYesYes
Available on macOSYesYes
Available on WindowsYesYes

Installation of Docker Engine on Fedora

To get Docker Engine up and running on Fedora, follow these simple steps:

  1. Update your system:

     sudo dnf update
    
  2. Install the Docker Engine package:

     sudo dnf install docker
    

  3. Start the Docker service:

     sudo systemctl start docker
    
  4. Enable the Docker service to start at boot:

     sudo systemctl enable docker
    
  5. Add yourself to the docker group:

     sudo usermod -aG docker $USER
    

  6. 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:

  1. 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
    
  2. Download the Docker Desktop from the Docker website.

  3. Open the rpm file and Install it.

  4. Open Docker Desktop and follow the on-screen instructions to complete the installation.

  5. To check the Docker Desktop installation and to run the "hello-world" image, run the below command:

     docker run hello-world
    

  6. 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!

  1. Begin by setting up the necessary environment:

    • Create a test directory.

    • Move into this directory.

    • Create a file without any extension.

  1. 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!'"]
    

  2. 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."

  1. You can also observe the created image in the Docker Desktop within the images section:

  2. Run the image:

     docker run my-hello-world
    

  3. To stop the container, use this command:

     docker stop <container>
    
  4. 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)

CommandDescription
docker pull <image>Pull an image from a container registry
docker imagesList all locally available images
docker run <image>Run a container from an image
docker psList running containers
docker ps -aList 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 lsList Docker networks
docker volume lsList Docker volumes
docker-compose upStart services defined in a docker-compose.yml
docker-compose downStop 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.