
The Complete Guide to Docker: Introduction to and Use of Container Technology for Beginners
- Development
- 10 Jun, 2024
What is Docker?
One of the technologies that has brought about the most innovative changes in the software development and distribution environment in recent years is Docker. Docker is a software platform that allows you to quickly build, test, and deploy applications. Docker packages software into standardized units called 'Containers', which contain everything needed to run the software, including libraries, system tools, code, and runtime.
Differences from existing virtualization methods
The existing virtual machine (VM) method runs multiple guest operating systems (Guest OS) through a hypervisor. This method had the disadvantage of requiring a heavy operating system to be installed on each virtual machine, which resulted in high resource consumption and slow execution speed.
On the other hand, Docker containers use a method of isolating processes while sharing the kernel of the host operating system. Therefore, there is no need for a separate guest operating system, making it much lighter and faster. Additionally, it can solve chronic problems such as “Does it work on my PC?” that arise due to differences between the development environment and the operating environment.
Docker's core concepts
To properly utilize Docker, you need to understand several key concepts.
1. Image
A Docker image is a read-only package that contains all the files and settings needed to run a container. It's easier to understand if you think of it as the 'executable file' of a program. Images can be downloaded from a registry such as Docker Hub, or created directly by writing a Dockerfile. Once created, the image is immutable, and using the same image, you can create a container with the same environment anywhere.
2. Container
A container refers to a state in which a Docker image is executed. If we compared an image to an executable file, a container can be compared to a running 'process'. You can create multiple independent containers from a single image, with each container running independently in an isolated environment. Changes made inside the container do not affect the original image, and those changes are lost when the container is deleted.
3. Dockerfile
Dockerfile is a script file for building Docker images. It sequentially describes a series of commands, such as specifying a base image, installing necessary packages, copying source code, and setting environment variables. By managing Dockerfiles as code (Infrastructure as Code), you can version control and automate infrastructure configuration.
4. Docker Hub
Docker Hub is the official public registry for sharing and storing Docker images. You can download and use numerous official images for free, including Ubuntu, Nginx, MySQL, and Node.js, and you can also upload your own images to share with others. If you need to share images only within your company, you can also build a separate private registry.
Docker installation and basic usage
Docker supports a variety of operating systems, including Windows, macOS, and Linux. You can download and install Docker Desktop (Windows, Mac) or Docker Engine (Linux) from the official website.
Once installation is complete, check the Docker version in the terminal or command prompt to confirm that it was installed properly.
docker --version
Most frequently used Docker commands
The essential commands you need to know to handle Docker are as follows.
docker pull [image name: tag]: Downloads an image from Docker Hub. If you omit the tag, the latest version (latest) will be downloaded.docker images: Check the list of Docker images currently stored locally.docker run [options] [image name]: Creates and runs a container based on the image.-d: Run in background (Detached mode)-p [host port]:[container port]: Port forwarding settings--name [container name]: Specifies the container name-v [host path]:[container path]: Mount volume (maintain data persistence)docker ps: Check the list of currently running containers. Adding the-aoption will show all stopped containers.docker stop [container ID or name]: Stops a running container.docker rm [container ID or name]: Deletes a stopped container.docker rmi [image ID or name]: Delete an image.
Practical use cases of Docker
Docker has gone beyond running single applications and has become a core element of modern software architectures and development processes.
1. Implementing Microservice Architecture (MSA)
Docker is indispensable in the microservice architecture, which divides a huge single application (monolithic) into small, independent services. Each service can be developed in a different language or framework, and can be packaged as a Docker container to deploy and scale independently.
2. Building CI/CD pipeline
Using Docker during continuous integration (CI) and continuous deployment (CD) ensures consistency in your build environment. Code written by developers is built into a Docker image, tested, and sequentially deployed to a staging environment and production environment. By using the same image in all environments, errors that occur during deployment can be dramatically reduced.
3. Configuring a temporary test environment
When testing new technologies or temporarily requiring infrastructure elements such as databases, you can immediately configure the environment with a single Docker command without a complicated installation process. This is very convenient as you can clean up your environment by simply deleting the container when you are finished testing.
In conclusion
Docker is a great tool that relieves the burden of managing complex infrastructure and allows developers to focus on the code itself. It may feel a bit unfamiliar when you first encounter it, but once you learn the basic concepts and commands, it will become a powerful weapon that can change the paradigm of your development and operating environment. Take your first step into the world of Docker today by running a simple web server or database container.







