볼륨을 활용한 데이터 지속성
개별 컨테이너의 수명이 끝난 후에도 애플리케이션 데이터가 유지되도록 Docker 볼륨을 구현합니다.
볼륨을 활용한 데이터 지속성은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Ephemeral Containers
When you run an application inside a Docker container, any data it creates or modifies is, by default, stored within the container's writable layer. This data is called ephemeral.
This means that if the container is stopped, removed, or crashes, all that valuable data is lost! This is a big problem for databases, user uploads, or configuration files that need to stick around.
We need a robust way to store data outside the container's lifecycle.
What are Docker Volumes?
Docker volumes are the preferred and most efficient way to persist data generated by and used by Docker containers. They are designed to solve the problem of ephemeral data.
- Volumes are managed by Docker itself, making them more robust and portable.
- They live on the host filesystem, but Docker handles their creation, management, and mounting to containers.
- Crucially, volumes are designed to outlive the container that created them, ensuring your data is safe and persistent.
Volumes vs. Bind Mounts
While volumes are the recommended approach, it's good to know the other main method for persistence:
- Volumes: Docker fully manages the lifecycle and location of the data on the host. This is the primary choice for most containerized applications.
- Bind Mounts: You control the exact mount point on the host filesystem. Docker doesn't manage the host data, giving you more control but less portability.
For this lesson, we'll focus on the powerful and flexible Docker volumes!
Creating Your First Volume
Before using a volume with a container, you can explicitly create a named volume. This gives you a clear, manageable reference.
Let's create a volume named my-data.
docker volume create my-dataAttaching Volume to Container
Now, let's run a container and attach our my-data volume to it. We'll mount it to /app/data inside the container using the -v flag.
When the container writes data to /app/data, that data will be saved in the my-data volume, ensuring it persists.
docker run -d --name my-app-with-data -v my-data:/app/data alpine sh -c "echo 'Hello from volume!' > /app/data/message.txt && sleep 3600"Accessing Volume Data
The data written to our volume is now persistent, even if the container stops or is removed. To prove it, let's run a new, temporary container and mount the same volume to it.
Then, we'll read the message.txt file we created earlier. Notice how the data is still there!
docker run --rm -v my-data:/app/data alpine cat /app/data/message.txtListing All Volumes
It's good practice to keep track of the volumes on your system. You can easily list all Docker volumes using a simple command. This helps you manage your persistent data storage and identify any unused volumes.
docker volume lsRemoving Unused Volumes
When you no longer need a volume, it's important to remove it to free up disk space. Remember, removing a volume permanently deletes all its data!
First, ensure no containers are actively using the volume. You might need to stop and remove any containers attached to it before removing the volume itself.
docker stop my-app-with-data
docker rm my-app-with-data
docker volume rm my-dataVolume Persistence Check
Containers are designed to be ephemeral. Which of the following commands is the primary way to ensure data created by a Docker container persists even after the container is removed?
Recap: Data Persistence
Great job! In this lesson, you learned about Docker volumes and why they are crucial for data persistence:
- Container data is ephemeral and typically lost when containers are removed.
- Docker volumes provide a managed, robust way to store data on the host, independent of the container's lifecycle.
- You learned how to create, use, inspect, list, and remove named volumes.
Now your Dockerized applications can keep their important data safe and accessible!
자주 묻는 질문
“볼륨을 활용한 데이터 지속성” 강의는 무료인가요?
네 — “볼륨을 활용한 데이터 지속성” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
“볼륨을 활용한 데이터 지속성”에서 뭘 배우나요?
개별 컨테이너의 수명이 끝난 후에도 애플리케이션 데이터가 유지되도록 Docker 볼륨을 구현합니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“볼륨을 활용한 데이터 지속성” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Docker 네트워크 유형 이해
- 컨테이너 네트워크 구성
- 볼륨을 활용한 데이터 지속성
- Docker Compose 네트워크로 컨테이너 연결하기