CodeGym /Courses /Docker SELF /Basic Docker Terms

Basic Docker Terms

Docker SELF
Level 10 , Lesson 0
Available

6.1 Images

To efficiently work with Docker, you need to understand a few key terms: images, containers, and registries. Let’s break them down and figure out what they’re for and how they interact with each other.

A Docker Image is a template used to create containers. An image contains all the necessary components to run an app: the operating system, the app itself, libraries and dependencies, plus configuration files. Drawing a parallel with OOP: a Docker image is like a class, and a container is an object of that class. Images are created using a Dockerfile — a text file that describes the steps to build an image.

Main characteristics of images:

  1. Layered structure: images are made up of several layers. There’s a base layer, and each subsequent layer represents changes compared to the previous one. This helps save space and reduces load time.
  2. Reusable: the same image can be used to create multiple containers.
  3. Portable: images can be transferred between different systems, making them perfect for development, testing, and deploying apps in various environments.

Examples of using images:

Creating your own image: you can create your own image by writing a Dockerfile, which specifies the settings for your app and its dependencies.

dockerfile

FROM ubuntu:latest
RUN apt-get update && apt-get install -y python3
COPY . /app
CMD ["python3", "/app/app.py"]

Using a ready-made image: you can use images available in Docker Hub to quickly deploy standard apps like web servers or databases.

Terminal

docker pull nginx 

This command downloads the nginx image from the public Docker Hub repository.

6.2 Containers

A Docker container is a running instance of an image. Containers isolate applications and their dependencies in a separate runtime environment, which allows them to run independently of the host system and other containers. Containers are lightweight because they use the host operating system's kernel instead of creating a separate kernel like virtual machines do.

Main characteristics of containers:

  • Isolation: containers isolate applications, ensuring they work independently and prevent dependency conflicts.
  • Lightweight: containers consume fewer resources compared to virtual machines since they don't require a separate operating system.
  • Fast startup: containers start and stop significantly faster than virtual machines, making them ideal for dynamic environments and scaling.

Examples of container usage:

Running a container: you can run a container from an image using the docker run command.

Terminal

docker run -d -p 80:80 --name mynginx nginx

Managing containers: Docker provides commands for managing containers: start, stop, restart, rm, and exec.

Terminal

docker stop mynginx
docker rm mynginx

You’ll learn all about these commands and their parameters in the next lectures.

6.3 Registries

Docker Registry is a storage for Docker images. Registries let developers and organizations store, manage, and distribute container images. There are public and private registries.

Main features of registries:

  • Public registries: like Docker Hub, offer access to a wide variety of images created by the community and official developers.
  • Private registries: are used to store and manage images within an organization, ensuring access control and security.
  • CI/CD Integration: registries can easily integrate with continuous integration and deployment systems, automating the process of building and deploying images.

Examples of using registries:

1. Docker Hub: public (and the most popular) Docker image registry. Offers access to lots of ready-to-use (and often verified, as seen from download stats) images.

Terminal

docker pull nginx
docker push myusername/myimage:tag  

2. Private registry: you can set up and use your own registry using Docker Registry.

Terminal

docker run -d -p 5000:5000 --name registry registry:2
docker tag myimage localhost:5000/myimage
docker push localhost:5000/myimage

Interaction of images, containers, and registries

These three components are closely related and form the foundation of working with Docker:

  • Creating an image: a developer creates an image using a Dockerfile and saves it locally.
  • Uploading an image to the registry: the image is uploaded to a registry (like Docker Hub or a private registry), where it is stored and becomes accessible to other users or systems.
  • Running a container: a user pulls an image from the registry and runs a container, which isolates the app and ensures it runs properly.

6.4 Orchestration

Orchestration is the process of managing a bunch of containers in a distributed environment. Orchestration tools help automate deployment, scaling, and management of containers.

  • Kubernetes: the most popular container orchestration platform that lets you manage a cluster of containers across different nodes.
  • Docker Swarm: a built-in Docker orchestration platform for creating and managing Docker clusters.
  • Orchestration features: automatic scaling, self-healing, network management, and load balancing.

6.5 Networks

Networks in Docker let containers communicate with each other and with the external world. Docker offers several types of networks for various use cases.

  • Bridge: the default network created by Docker. Containers in the bridge network can communicate with each other.
  • Host: the container uses the network interfaces of the host machine, getting direct access to them.
  • Overlay: used for creating networks across multiple Docker daemons. Required for orchestration.
  • None: disables all of the container's network interfaces. Useful for isolated tasks.

6.6 Volumes

Volumes are a mechanism for persistent storage of container data. They allow you to save data outside the container so that the information isn't lost when the container restarts or is removed.

  • Creating a volume: volumes are created using the docker volume create command.
  • Mounting a volume: volumes are attached to containers with the -v flag when starting up.
  • Advantages: volumes provide convenient data storage and sharing between containers, as well as better performance compared to bind mounts.

Important! A volume is like a virtual hard drive that can be connected to a virtual machine or container. It’s usually stored on the host operating system as a regular file.

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION