Docker & Kubernetes for Developers · レッスン

Dockerボリュームによるデータの永続化

Dockerボリュームとバインドマウントによって、コンテナのライフサイクルを超えてデータを保持し、ホストとコンテナ間でファイルを共有する方法を学びます。

レッスン 4/413 ステップ

「Dockerボリュームによるデータの永続化」はCoddyKit上の無料Docker & Kubernetes for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDocker & Kubernetes for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Containers Are Ephemeral

When a container is removed, everything written inside its writable layer is gone. For databases, uploads, or logs you need storage that survives the container.

Two Storage Options

Docker offers two main mechanisms:

  • Volumes: managed by Docker, stored in a dedicated area
  • Bind mounts: map a specific host folder into the container

Volumes are the recommended default.

Creating a Volume

Create a named volume with docker volume create. Docker manages where it physically lives.

docker volume create app_data

Mounting a Volume

Attach the volume to a container path with -v. Anything written to that path persists in the volume.

docker run -d -v app_data:/var/lib/data my_app

Bind Mounts for Development

A bind mount maps a host directory into the container, great for live-editing source code during development.

docker run -v /home/me/project:/app node:20

Listing and Inspecting Volumes

See all volumes with docker volume ls, and view details, including the mount point, with docker volume inspect.

docker volume ls
docker volume inspect app_data

Volumes in Compose

In docker-compose.yml you declare volumes once and reference them in services. Use single quotes and indentation, never tabs.

services:
  db:
    image: postgres:16
    volumes:
      - db_data:/var/lib/postgresql/data
volumes:
  db_data:

Sharing a Volume Between Containers

Multiple containers can mount the same volume to share files, for example an app writing files and a backup container reading them.

docker run -v shared:/data writer
docker run -v shared:/data reader

Read-Only Mounts

Append :ro to mount a volume read-only when a container should never modify the data, adding a safety guard.

docker run -v config:/etc/app:ro my_app

Backing Up a Volume

Back up a volume by running a throwaway container that tars its contents to the host.

docker run --rm -v app_data:/data -v $(pwd):/backup \
  alpine tar czf /backup/data.tar.gz /data

Cleaning Up Unused Volumes

Orphaned volumes waste disk. Remove a named one with docker volume rm, or clear all unused volumes with docker volume prune, carefully.

docker volume prune

Quick Check

Test your understanding of Docker storage.

Recap

You learned to persist data in Docker:

  • Containers are ephemeral; use volumes or bind mounts for durable data
  • Mount with -v name:/path; use bind mounts for live dev
  • Declare volumes in Compose and share them between containers
  • Back up, mount read-only, and prune unused volumes

Volumes let your databases and files outlive any single container.

無料で開始

AI チューターと学ぶ Docker & Kubernetes for Developers — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
48

よくある質問

「Dockerボリュームによるデータの永続化」レッスンは無料ですか?

はい。「Dockerボリュームによるデータの永続化」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Docker & Kubernetes for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。

「Dockerボリュームによるデータの永続化」で何を学びますか?

Dockerボリュームとバインドマウントによって、コンテナのライフサイクルを超えてデータを保持し、ホストとコンテナ間でファイルを共有する方法を学びます。 ブラウザで直接実行するハンズオンコードでDocker & Kubernetes for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Docker & Kubernetes for Developersを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDocker & Kubernetes for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「Dockerボリュームによるデータの永続化」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDocker & Kubernetes for Developersレッスンでコードを書いて実行できますか?

はい。すべてのDocker & Kubernetes for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. イメージ用Dockerfileの作成
  2. カスタムDockerイメージのビルド
  3. Composeによるマルチコンテナアプリ
  4. Dockerボリュームによるデータの永続化
← Docker & Kubernetes for Developersに戻る