LoginSignup
4
5

More than 5 years have passed since last update.

docker export や commit では Volume 設定のデータが保存(バックアップ)できない。

Last updated at Posted at 2015-04-21

準備

PostgreSQL9.3 の公式イメージでコンテナ実行。

$ docker run -d --name db postgres:9.3

デフォルトのデータ保存先を確認すると、ファイルができている。

$ docker exec db ls -l /var/lib/postgresql/data/
total 100
drwx------ 5 postgres postgres  4096 Apr 17 10:57 base
drwx------ 2 postgres postgres  4096 Apr 17 10:57 global
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_clog
-rw------- 1 postgres postgres  4506 Apr 17 10:57 pg_hba.conf
-rw------- 1 postgres postgres  1636 Apr 17 10:57 pg_ident.conf
drwx------ 4 postgres postgres  4096 Apr 17 10:57 pg_multixact
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_notify
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_serial
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_snapshots
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_stat
drwx------ 2 postgres postgres  4096 Apr 17 10:59 pg_stat_tmp
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_subtrans
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_tblspc
drwx------ 2 postgres postgres  4096 Apr 17 10:57 pg_twophase
-rw------- 1 postgres postgres     4 Apr 17 10:57 PG_VERSION
drwx------ 3 postgres postgres  4096 Apr 17 10:57 pg_xlog
-rw------- 1 postgres postgres 20564 Apr 17 10:57 postgresql.conf
-rw------- 1 postgres postgres    37 Apr 17 10:57 postmaster.opts
-rw------- 1 postgres postgres    85 Apr 17 10:57 postmaster.pid

docker export でデータ保存ができるか試してみる

コンテナをファイル出力する

$ docker export db > backup.tar

ファイルからイメージをインポート

$ cat backup.tar | docker import - restore
3ca20306e2fea0682e3a12900f198eb0038ac7228b1c973e7b3e5ae16876d24b

イメージができてるか確認

$ docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
restore                      latest              3ca20306e2fe        2 minutes ago       208.4 MB
postgres                     9.3                 b4749b21d4c1        2 weeks ago         212.9 MB
debian                       wheezy              1265e16d0c28        2 weeks ago         84.98 MB

作成したイメージからコンテナを実行してデータができてるか確認すると、

$ docker run -it --name restore_db restore /bin/bash
root@82f874b2278f:/# ls -l /var/lib/postgresql/data/
total 0

できてない。。

docker commit でデータ保存ができるか試してみる

  • docker export で作ったコンテナとイメージを削除をしておく。
  • 前述の準備をしておく。

コンテナからイメージを作成する

$ docker commit db restore

イメージができてるか確認

$ docker images
restore                      latest              ea4bddb3f40d        8 seconds ago       212.9 MB
postgres                     9.3                 b4749b21d4c1        3 weeks ago         212.9 MB
debian                       wheezy              1265e16d0c28        3 weeks ago         84.98 MB

作成したイメージからコンテナを実行してデータができてるか確認すると、

$ docker run -it --name restore_db restore /bin/bash
root@43cb817de65b:/# ls -l /var/lib/postgresql/data/
total 0

できてない。。

4
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5