Docker Tutorial

Foundational Concept - Docker

Build, Ship, Run - Repeat.

Swati Meher
Python’s Gurus

--

swameher from Canva

Let’s understand about Docker. I’ll begin with the foundational concepts and then move on to a practical demonstration of applications.

Docker is an open platform designed to streamline the development, shipping, and running of applications using containers. The key benefits of Docker include increased productivity, reduced system errors, and improved efficiency. Being an independent tool, Docker is compatible with multiple programming languages such as Java, Python, PHP, Node.js, and more.

Let’s discuss the purpose of using Docker, Imagine a scenario where Developer 1 has been working on a project for years. Developer 2 then tries to run the same code on their system but encounters errors. The issue arises because, over time, the technology has evolved. As a result, the code works on Developer 1’s system but not on Developer 2’s, and the tester would likely face similar issues. Docker solves this problem effectively.

A Docker container packages everything related to a project, including code, runtime, system tools, system libraries, and settings — all with specific versions. This ensures that the code runs consistently across different environments. With Docker, developers can build, run, and share projects seamlessly. Moreover, Docker is regularly updated with the latest technology versions and is free to use for small businesses and students.

Docker containers store the complete project code, which is pushed to a server. When Developer 2 pulls the code from the Docker container, it runs smoothly without any errors since Docker maintains the most up-to-date versions required for the project.

The key benefit of learning Docker is developers would rely on it for deploying projects, improving productivity, and seamlessly integrating with system requirements and it's a must for skilled developers to learn Docker.

Docker Setup:

  • Visit the official Docker website and download the appropriate version for your operating system.
  • Run the installer and follow the on-screen instructions. During installation, leave the configurations as default unless you have specific requirements.
  • Once installed, open the Command Prompt (CMD) and type the following command:
docker --version
  • If Docker is installed correctly, it will display the version. If not, you may need to troubleshoot or reinstall.

Core concepts:

Here, we’ll discuss images and containers.
In simple terms, images serve as templates for a project, containing essential components like tools, libraries, and code. Containers allow you to run an instance of these images.

Docker Images:

  • It’s a ready-to-use template that contains everything needed to run the code, including source codes, libraries, external dependencies, and tools.
  • The template is read-only, meaning the included source code, dependencies, and tools cannot be modified. It means Images can’t be updated.
  • To make changes to the image, a new image must be created.
  • Images can’t be run directly.

Docker Containers:

  • A container is a runnable instance of an image that you can create, start, stop, move, or delete using the Docker API or CLI.
  • Containers can be connected to one or more networks, have storage attached, or even be used to create a new image based on their current state. And it is an isolated process.
  • A container is defined by its image and any configuration options provided during creation or startup.
  • When a container is removed, any non-persistent changes to its state are lost.

Docker Hub:

Docker Hub is an online platform accessible via a browser, primarily used for managing and downloading images. It allows you to pull and use pre-built parent images.

For example, if you want to create a Docker image for a Django application, you’ll need essential tools like Python, Django, and additional dependencies. While Python is crucial, building an image from scratch isn’t practical due to its extensive modules. Instead, you can download a pre-built Python image from Docker Hub, where instructions are provided on how to install or pull the image.

It’s important to understand the two types of images:

  1. Custom Images: Created by us using application code.
  2. Parent Images: Pre-built images available on Docker Hub.

Docker Desktop:

Docker Desktop functions similarly to Docker Hub. You can search for “Python” in the search bar to find images along with instructions for pulling them into your system. Once downloaded, these images appear in the “Images” tab, and after running them, they’ll be visible in the “Containers” section.

The key difference between Docker Hub and Docker Desktop is that Docker Desktop offers more features and functionalities, although both platforms serve the same purpose — pulling, running, and managing images.

Enjoy this Docker tutorial? Follow me on Medium for more tech insights! Have feedback or a topic you’d like covered? Share your thoughts in the comments. In the next article, I’ll dive deeper into parent images and custom images for further clarity.

--

--

Swati Meher
Python’s Gurus

Data Analyst | Gadget Lover | Hoping to reach 300 Followers here.