Skip to content
프로젝트

소개

docker-export 및 docker-commit 명령은 컨테이너 볼륨을 저장하지 않습니다. 이 스크립트를 사용해 컨테이너 볼륨을 저장하고 불러오세요.

시스템 및 인프라

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Build Status

docker-volumes.sh

The docker export and docker commit commands do not save the container volumes. Use this script to save and load the container volumes.

Usage

Usage: docker-volumes.sh [-b|--bind] [-V|--volume] [-v|--verbose] CONTAINER save|load TARBALL
Options:
-b, --bind	Use only bind-mounts
-V, --volume	Use only internal volumes
-v, --verbose	Be verbose
-h, --help	Show this help

Podman

To use Podman instead of Docker, prepend DOCKER=podman to the command line to set the DOCKER environment variable.

NOTE: With rootful podman you may want to check the checkpoint/restore functionality

Example

Let's migrate a container to another host with all its volumes.

# Stop the container 
docker stop $CONTAINER
# Create a new image
docker commit $CONTAINER $CONTAINER
# Save and load image to another host
docker save $CONTAINER | ssh $USER@$HOST docker load 

# Save the volumes (use ".tar.gz" if you want compression)
docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar

# Copy volumes to another host
scp $CONTAINER-volumes.tar $USER@$HOST:

### On the other host:

# Create container with the same options used in the previous container
docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER

# Load the volumes
docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar

# Start container
docker start $CONTAINER

To get the command used to create a container:

  • podman: podman container inspect -f '{{ range .Config.CreateCommand }}{{ printf "%s " . }}{{ end }}' $CONTAINER
  • docker lacks this functionality.

Notes

  • This script could have been written in Python or Go, but the tarfile module and the tar package lack support for writing sparse files.
  • We use the Ubuntu Docker image with GNU tar v1.29+ that uses SEEK_DATA & SEEK_HOLE to manage sparse files.
  • To see the volumes that would be processed run docker container inspect -f '{{json .Mounts}}' $CONTAINER and pipe it to either jq or python -m json.tool.

BUGS / LIMITATIONS

  • The --volumes-from option is buggy in Podman < 4.7.0
  • Make sure the volumes are defined as such with the VOLUME directive. For example, the Apache image lacks them, but you can add them manually with docker commit --change 'VOLUME /usr/local/apache2/htdocs' $CONTAINER $CONTAINER

관련 프로젝트 살펴보기

불러오는 중…