Code Monkey home page Code Monkey logo

docker-volumes.sh's Introduction

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

docker-volumes.sh [-v|--verbose] CONTAINER [save|load] TARBALL

Podman

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

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

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 / Features

  • 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

docker-volumes.sh's People

Contributors

ricardobranco777 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-volumes.sh's Issues

Cannot open: Is a directory

Hi

thanks for sharing your script.

I'm having trouble on using it, am I doing right?

sudo ./docker-volumes.sh -v mynodered save nodered-copy.tar

This is the container I'm trying to save

container-id        nodered/node-red-docker:v8                                "npm start -- --user…"   5 weeks ago         Up About an hour                             mynodered

I tried using name (mynodered) and container-id, with no success.

The error I get is

tar: //tmp.elTZ0QK1kg/nodered-copy.tar: Cannot open: Is a directory
tar: Error is not recoverable: exiting now

What can I do?

Thanks

Is Docker version 18.09-9 supported ?

Hi.

I'm trying to use this great script but currently is not saving the volumes.

Docker version 18.09.9-ce, build 039a7df on both instances.

Steps:

docker run -it --name http -d -p 9098:80 -v data-volume:/usr/local/apache2/htdocs httpd:2.4

docker inspect -f '{{ .Mounts }}' http [{volume data-volume /var/lib/docker/volumes/data-volume/_data /usr/local/apache2/htdocs local z true }]

docker stop 6d70038e617b

docker commit 6d70038e617b web

docker save -o web.tar web

docker-volume.sh 6d70038e617b save web_volumes.tar

Switch to another host/machine

docker load -i web.tar

docker create -p 9098:80 --name web web

docker-volumes.sh -v web load web_volume.tar

usr/local/apache2/htdocs/
usr/local/apache2/htdocs/index.html

docker start web

docker inspect -f '{{ .Mounts }}' web []

The volumes is not loaded. Any help is appreciate.

Thanks in advance.

run

when run sh file show error :

docker-volumes.sh: 14: docker-volumes.sh: [[: not found
docker-volumes.sh: 14: docker-volumes.sh: dockermagento2_web_1: not found
docker-volumes.sh: 19: docker-volumes.sh: Syntax error: "(" unexpected (expecting "then")

docker-volumes.sh command not found

I am trying your script and it give me error docker-volumes.sh command not found
and do let me know what to used instead of this $USER@$HOST I mean username and host IP of other host machine or simply as it is ??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.