What is Docker?
In this tutorial, we’ll discuss what Docker is and why it is used by developers worldwide.
When a developer tries to set up or share a project, one of the biggest challenges is managing the dependencies and different software versions the project requires. Consider the following situation: We are working on a software project and we wish to share the code files with another developer, named Bob, for review, testing, and debugging. We may have certain packages and libraries already installed on our computer that Bob may not. When trying to share the project, because Bob doesn’t have the same packages installed, he has to install them to avoid running into any issues. Docker solves this problem by allowing us to send a clone of our machine, including all installed libraries and frameworks, thereby allowing Bob to skip having to install the libraries on his machine and proceed with working with the code.
Docker, created by Docker, Inc. in 2013, helped millions of developers worldwide in creating independent and isolated environments to launch and deploy their applications. These environments are called containers. After Docker was created, developers were able to use the following quote: “If it works on my machine, it will work everywhere.”
How does Docker work?
Docker works by creating an image file of a project, which later helps us run multiple independent and isolated containers simultaneously. An isolated container means if something happens to one container, it won’t affect the others. Because of this, we can run multiple versions of the same application at once on a single PC.
The image files are created using a file called a “Dockerfile.” A Docker file is a script containing instructions on building a Docker image. Each instruction in the Docker file adds a layer to the image, allowing us to define the operating system, install necessary software packages, copy project files, and set up the application environment.
By following the instructions in the Dockerfile, Docker builds an image that encapsulates all the dependencies and configurations our project needs. This image can then be used to launch containers, ensuring that our application runs consistently across different environments.
A common misconception about Docker
There’s a misconception about Docker: it is very similar to a virtual machine. Docker is not a virtual machine (VM). While both Docker containers and virtual machines serve to isolate applications, they operate in fundamentally different ways.
To learn more about this, check out the table below:
Docker Containers | Virtual Machines |
---|---|
- Running multiple containers on a local system has a low impact on the OS. It uses a small amount of disk space and is fast. | - VMs have a high impact on the local system as they will consume more RAM and disk space, making the system slow if we run multiple VMs at once. |
- Sharing, destroying, and creating a Docker container is extremely easy as it encapsulates everything needed to run an application, including the code, runtime, libraries, and dependencies, ensuring consistency across different environments. | - Sharing, destroying, and creating a VM can be challenging as it requires managing and maintaining a full operating system, allocating significant resources, and dealing with complex setup and configuration processes. |
- Docker containers encapsulate apps instead of full machines, meaning all necessary parts of an application including its code, libraries, and dependencies, are loaded into a single container. | - VMs encapsulate a whole machine. This includes the entire operating system and application and its dependencies. |
Docker Architecture
Docker architecture consists of several components that work together to facilitate the creation, deployment, and management of containers. These key components include:
- Docker Engine
- Docker Images
- Docker Containers
- Docker Registries
Docker Engine
The Docker engine is the most important component of Docker, also responsible for running the containers. A Docker engine consists of:
Docker Daemon
: Manages objects like images, containers, networks, and volumes.Docker Client
: The Command line interface (CLI) that helps the user to interact with Docker and its components. Commands likeDocker run
,Docker build
,Docker pull
, andDocker push
are sent from the Docker Client to the Docker Daemon.REST API
: Provides a way to communicate with Docker Daemon.
Docker Images
Docker images are templates used to create containers. These images contain the application along with all the necessary dependencies and packages required for it to run. A Docker image packages everything the application needs into a single, portable unit, ensuring consistency across different environments.
Docker Containers
Docker containers are instances of a Docker image. They contain the application and its dependencies, providing a constant environment for running the application across different systems. It’s also important to understand the cycle of a Docker container:
- Create: A container is created from a Docker image.
- Start: The container is started, running the specified command or application.
- Stop: The container is stopped, pausing the application.
- Restart: The container is restarted.
- Pause/Unpause: The container’s processes are paused or resumed.
- Destroy: The container is removed from the system.
Docker Registries
Docker Registries are repositories for storing and distributing Docker images. They allow users to share images within an organization or publicly. The Docker registry is divided into two parts:
- Docker Hub: Docker Hub is the default public registry provided by Docker. It hosts a vast collection of official and community-contributed images.
- Private repositories: Users can also set up private repositories which can only be accessed by people who have permission to access the repository. Usually, organizations choose this repository to keep their data safe.
Conclusion
We have covered the basics of what Docker is. You should now be familiar with basic Docker concepts such as Docker architecture, Docker Images, Docker Engines, and Docker containers. Docker is an important tool used by developers to deploy, ship, test, and manage their projects. Docker has made the life of a developer much easier and is also very efficient to use.
To learn more concepts about computer science, check out these articles.
Author
'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'
Meet the full teamRelated articles
Learn more on Codecademy
- Skill path
Code Foundations
Start your programming journey with an introduction to the world of code and basic concepts.Includes 5 CoursesWith CertificateBeginner Friendly4 hours - Career path
Full-Stack Engineer
A full-stack engineer can get a project done from start to finish, back-end to front-end.Includes 51 CoursesWith Professional CertificationBeginner Friendly150 hours