Daily-It

개발, AI, 인프라, 자동화와 일상 IT 제품 후기를 직접 써보며 정리하는 기술 블로그입니다.

Docker Concepts and Installation Guide: From Container Basics to Ubuntu Setup

Summary

Docker is an application and execution environment Container It is a platform that packages and runs units. It is widely used in development, DevOps, and CI/CD environments as it can reduce the difference between the development environment and the operating environment and make the deployment process consistent.

In this article, we summarize the basic concepts of Docker, the difference between virtual machines (VMs) and containers, core components, how to install Docker Engine on Ubuntu, how to use Docker Desktop on Windows/macOS, Dockerfile and Docker Compose examples, and common mistakes in production.

Based on: Docker official documentation, Docker Engine/Desktop release notes, Ubuntu package information, Docker Compose documentation, Podman official site, and search results were checked together. Docker’s installation commands, package names, and support policies may change depending on the version, so it is recommended to check the official documentation before actual installation.

Table of Contents

Background

One of the common problems developers face is:

“It runs fine on my PC, but gives an error on the server.”

This problem is usually caused by differences in operating systems, runtimes, libraries, environment variables, network settings, file paths, etc. Docker reduces environmental differences by bundling the elements needed to run an application into an image and executing it as a container.

The advantages of using Docker include:

  • The difference between the development environment and the production environment can be reduced.
  • Standardize how your applications run.
  • It becomes easier to configure testing, deployment, and CI/CD pipelines.
  • Multiple services can run together with Docker Compose.

How This Guide Was Checked

This article is not simply summarized based on existing experiences, but has been strengthened based on the following materials.

Verified data What was reflected
Docker official concepts document Image, container, registry, Dockerfile, Compose concepts
Docker Engine Ubuntu installation documentation Register the official APT repository, docker-ce Series package installation method
Docker Engine release notes Confirms that the Docker Engine 29 family is available as the latest release line
Docker Desktop release notes Docker Desktop updates are released gradually, and older versions may have download restrictions.
Docker Compose installation documentation In the latest environment docker compose Confirm that the use of CLI plugins in the form of
Ubuntu package information Ubuntu distribution package docker.ioConfirm that exists separately
Podman official site and search results Check the flow where Podman is mentioned as a Docker alternative.

The purpose of this article is to help beginners with Docker understand the installation and basic usage flow. Therefore, rather than covering all the changes in a specific release in depth, we focused on the latest trends that affect installation and operation decisions.

Details

What Is Docker?

Docker is a container-based application execution platform. Containers run application processes in an isolated environment, but do not launch an entire operating system like a virtual machine.

Key concepts that frequently appear in Docker include:

concept Description
Image A read-only template containing the files, libraries, and settings needed to run the application.
Container Execution environment of the actual process unit that executed the image
Docker Engine Core runtime that creates and runs containers
Docker CLI docker run, docker build, docker ps Tools to enter the same command
Registry A repository that stores and distributes images. A representative example is Docker Hub.
Docker Compose Tool to define multiple container services as YAML files and run them together

Docker vs. Virtual Machines

Both Docker containers and virtual machines provide isolated execution environments, but their structures are different.

Category virtual machine VM Docker container
Isolation method Run Guest OS on top of hypervisor Process isolation by sharing the host OS kernel
boot speed relatively slow speed
resource usage greatness relatively small
Representative uses OS unit isolation, strong isolation environment Unification of application packaging, distribution, and development environment
example VMware, VirtualBox, Hyper-V Docker, Podman

However, this does not mean that containers are always safer than VMs. Containers share the host kernel, so in security-critical environments, permissions, network, volume mounts, and image reliability must be reviewed.

Installing Docker Engine on Ubuntu

In Ubuntu, it is recommended to register Docker’s official APT repository and then install Docker Engine. in your distribution’s default repository. docker.io Packages are available, but official repositories are often more appropriate if you want to use the latest Docker Engine and Compose plugins.

It is recommended that you understand the following differences before installation:

Category Description suitable case
docker-ce Docker Community Edition package provided by Docker official repository If you want to install the latest Docker Engine, Buildx, and Compose plugins based on the official documentation
docker.io Docker packages provided by Ubuntu distribution repositories. Follow your distribution’s package policy, or if your organization standard is Ubuntu repository packages.

Docker official documentation refers to existing installed docker.io, docker-compose, docker-compose-v2, podman-docker, containerd, runc etc. may conflict with official Docker Engine packages, we provide procedures for removing conflicting packages before installation. If you are working on an existing server, you should check your current containers and package dependencies before completely deleting them.

The example below is the installation flow based on Docker’s official documentation.

# 1. 기존 패키지 정보 갱신 및 필수 패키지 설치
sudo apt update
sudo apt install -y ca-certificates curl

# 2. Docker 공식 GPG 키 저장 경로 생성
sudo install -m 0755 -d /etc/apt/keyrings

# 3. Docker 공식 GPG 키 추가
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# 4. Docker 공식 APT 저장소 등록
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

# 5. 패키지 정보 갱신
sudo apt update

# 6. Docker Engine 및 관련 플러그인 설치
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

After installation, you can check if Docker is operating normally with the following command.

sudo docker run hello-world

If it was installed properly, Docker downloads the test image and Hello from Docker! Prints a message.

Running Docker without sudo

Docker commands every time on Linux sudo To run without the current user docker You can add them to groups.

sudo usermod -aG docker $USER

You can then log out and log back in, or apply the group change to the current session with the command below.

newgrp docker

Then check with the following command:

docker run hello-world

Things to note docker The problem is that group privileges can effectively lead to elevated privileges on the host system. On production servers, user permission policies must be carefully defined.

Installing Docker on Windows and macOS

On Windows and macOS, usually Docker DesktopInstall . Docker Desktop comes with Docker Engine, Docker CLI, Docker Compose, and GUI management tools.

Docker Desktop does not have the same installation experience as Docker Engine for servers. To run Linux containers on Windows/macOS, we internally use a virtualization layer or a WSL 2-based environment. Additionally, according to the Docker Desktop release notes, updates may be rolled out gradually, and the latest version may not be immediately visible to all users.

The installation flow is as follows:

  1. Download Docker Desktop from the Docker official site.
  2. Run the installation file appropriate for your operating system.
  3. For Windows, it is common to use a WSL 2-based execution environment.
  4. After installation, run the following command in terminal:
docker version
docker run hello-world

Because Windows and macOS have different internal structures from Linux, Docker Desktop provides a Linux container execution environment through a virtualization layer or WSL 2.

Basic Docker Commands

The frequently used commands after installing Docker are as follows:

# Ubuntu 컨테이너를 대화형 터미널로 실행
docker run -it ubuntu bash

# 실행 중인 컨테이너 목록 확인
docker ps

# 전체 컨테이너 목록 확인
docker ps -a

# 이미지 목록 확인
docker images

# 컨테이너 중지
docker stop <container_id>

# 컨테이너 삭제
docker rm <container_id>

# 이미지 삭제
docker rmi <image_id>

<container_id>and <image_id>must be changed to suit the actual environment.

How Docker Images and Containers Run

The most confusing part when using Docker for the first time is the relationship between images and containers. An image is an executable template, and a container is an instance that actually runs the image.

The general flow is as follows:

Dockerfile 작성
  ↓
docker build로 이미지 생성
  ↓
docker run으로 컨테이너 실행
  ↓
docker logs / docker exec로 상태 확인
  ↓
docker stop / docker rm으로 정리

For example, running the Nginx image would look like this:

docker run -d --name sample-nginx -p 8080:80 nginx:stable

in your browser http://localhost:8080When you connect to , Nginx inside the container responds. For cleanup, use the following command:

docker stop sample-nginx
docker rm sample-nginx

A Simple Dockerfile Example

Dockerfile is a build definition file for creating an application image. Below is the simplest example of serving a static HTML file with Nginx.

FROM nginx:stable
COPY ./index.html /usr/share/nginx/html/index.html

in the same directory index.htmlCreate .

<!doctype html>
<html lang="ko">
<head>
  <meta charset="utf-8">
  <title>Docker Test</title>
</head>
<body>
  <h1>Hello Docker</h1>
</body>
</html>

Build and run the image.

docker build -t sample-nginx-page .
docker run -d --name sample-page -p 8080:80 sample-nginx-page

Confirmation can be done with the following command:

curl http://localhost:8080

After testing, clean up the container.

docker stop sample-page
docker rm sample-page

This is a simple example to the extent that it is reproducible with Docker. Your production environment requires additional considerations for image tagging, security scanning, deployment methods, log collection, and reverse proxy configuration.

Docker Compose Example

Docker Compose allows you to define multiple containers in a single YAML file. In the latest Docker environment, the old docker-compose In the form of a Docker CLI plugin rather than a command docker compose The flow using commands is common.

For example, here’s a basic example of running a PostgreSQL container:

services:
  postgres:
    image: postgres:16
    container_name: sample-postgres
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: sampledb
      POSTGRES_USER: sampleuser
      POSTGRES_PASSWORD: "****"
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data:

Sensitive information such as passwords, tokens, and API keys do not expose the actual values ​​even in the examples. ****It should be written as . In a real production environment .env We recommend using File, Secret Manager, CI/CD Secret features, etc.

The execution command is:

docker compose up -d

To stop, use the following command:

docker compose down

If you want to delete a volume as well, you can use the following command, but be careful because it will delete data.

docker compose down -v

Best Practices

Use official and trusted images

Docker Hub has a variety of images, but not all of them are secure or up-to-date. Whenever possible, you should use official images or images from trusted vendors.

Specify tags clearly

In an operational environment latest We recommend avoiding using tags alone.

image: postgres:16

Specifying the version like this can reduce failures due to unexpected version changes.

Separate environment variables and configuration files

Fixing environment-specific settings within an image makes it difficult to separate development, testing, and production environments. Values ​​that vary depending on the environment, such as database address, port, and execution mode, are stored in Docker Compose. environment, .env We recommend using the configuration management features of your file and distribution system.

In the documentation example, if a sensitive value is needed, the actual value is not written but masked as follows:

environment:
  POSTGRES_PASSWORD: "****"

In an operational environment, simple .env Files alone may not be sufficient; you should review the Secret Manager or CI/CD Secret functionality appropriate for your organization’s deployment.

Manage volumes and networks clearly

Services that store state, such as databases, should use volumes to ensure that data persists even when containers are deleted.

volumes:
  postgres_data:

Additionally, when multiple services work together, it’s a good idea to understand Docker Compose network configuration and how they communicate using service names.

Review security settings in your production environment

The following items must be reviewed in your production environment:

  • container permissions
  • Whether to run as root user
  • Host directory mount range
  • Whether Docker socket is exposed?
  • Image Vulnerability Scan
  • Network port public range
  • Log and monitoring settings

Consider alternatives such as Docker and Podman together.

Although Docker is the most widely known tool in the container ecosystem, it is not the only solution for all environments. In recent container operating environments, alternatives such as Podman are also being considered.

Category Docker Podman
usability Wide ecosystem of Docker Desktop, Docker Engine, and Docker Compose Provides a similar experience to Docker CLI
Daemon Structure Docker daemon-centric architecture Features a daemonless structure
suitable case Standardization of development environment, local development based on Compose, utilization of Docker Hub ecosystem Rootless containers, Linux server-centric operation, environments where specific security policies are important

For beginners or general development environments, it’s easy to get started with Docker. However, alternatives such as Podman can be compared depending on the security policy of the operating environment, rootless requirements, and Kubernetes connection method.

Common Mistakes

Confusing docker.io and docker-ce

On Ubuntu apt install docker.ioYou can also install it, but according to Docker’s official documentation, after registering the official repository, docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin, docker-compose-pluginWe will guide you through how to install.

Depending on your organization or server policy, distribution packages may be available, so your choice should be based on your installation purpose and maintenance policy.

Unconditionally grant permission to use Docker without sudo

docker Adding users to groups is convenient, but can have a similar security effect to granting strong permissions. Permission policies for personal development environments and production servers must be approached differently.

Use containers like VMs

Continuously accessing the inside of the container and manually changing settings has poor reproducibility. If possible, it is recommended to manage the execution environment like code with Dockerfile, Compose file, and environment variables.

Store data only inside the container

Containers can be deleted. Data that needs to be persisted, such as databases or uploaded files, must be stored on volumes or external storage.

FAQ

What should I do if I get a permission error after installing Docker on Ubuntu?

permission denied while trying to connect to the Docker daemon socket If an error occurs, it means that the current user does not have permission to access the Docker daemon socket. In the development environment, users docker Add to the group and log in again newgrp dockerYou can solve this by running .

sudo usermod -aG docker $USER
newgrp docker

step, docker Because groups can have high privileges, you should first review user rights policies on production servers.

What should I check if the docker compose command doesn’t work?

In the latest Docker installation method, Compose is separate docker-compose They are often provided as Docker CLI plugins rather than binaries. Verify that the Compose plugin is installed with the following command:

docker compose version

If you install from Ubuntu using the official repository method docker-compose-plugin Check if the package is included.

sudo apt install docker-compose-plugin

Can I use Docker on a Linux server without Docker Desktop?

it’s possible. On Linux servers, Docker Engine is generally installed and used, not Docker Desktop. Docker Desktop is more of a tool for easy use of Docker in Windows/macOS development environments, and in Linux server operating environments, it is common to install only the Docker Engine and Compose plugins.

What command do I use to check Docker installation?

After installation, you can check the Docker CLI and Docker Engine status with the following commands:

docker version
docker run hello-world

docker run hello-worldis the most basic verification method to download a test image and check whether the container can run.

Conclusion

Docker is a tool that standardizes the application execution environment as a container, making the development, testing, and deployment processes consistent. In particular, it reduces problems caused by differences in development environments and provides great advantages in CI/CD and microservice environments.

In Ubuntu, it is common to register the official Docker repository and then install the Docker Engine and Compose plugin, while in Windows and macOS, the easiest method is to use Docker Desktop.

However, Docker is not just a simple execution tool, but a platform that requires consideration of permissions, network, volume, and image security. Get started quickly in your development environment, but be sure to review your security and maintenance policies in your production environment.

References

  • Docker Docs: What is Docker? — https://docs.docker.com/get-started/docker-overview/
  • Docker Docs: Install Docker Engine on Ubuntu — https://docs.docker.com/engine/install/ubuntu/
  • Docker Docs: Linux post-installation steps for Docker Engine — https://docs.docker.com/engine/install/linux-postinstall/
  • Docker Docs: Docker Desktop — https://docs.docker.com/desktop/
  • Docker Docs: Docker Compose installation — https://docs.docker.com/compose/install/
  • Docker Docs: Dockerfile reference — https://docs.docker.com/reference/dockerfile/
  • Docker Docs: Docker Engine release notes — https://docs.docker.com/engine/release-notes/
  • Docker Docs: Docker Desktop release notes — https://docs.docker.com/desktop/release-notes/
  • Ubuntu Packages: docker.io — https://packages.ubuntu.com/search?keywords=docker.io
  • Podman Official Site — https://podman.io/