Skip to main content

Transfer/Move a Docker Image

Using Export Command

Sample: osslab-dekiwiki

docker run -d -p 8880:80 \
-v /etc/localtime:/etc/localtime:ro \
-v $PWD/vol/data:/data \
-v $PWD/vol/var-lib-mysql:/var/lib/mysql \
-v $PWD/vol/var-log-httpd:/var/log/httpd \
-v $PWD/vol/var-log-dekiwiki:/var/log/dekiwiki \
-v $PWD/vol/var-www-dekiwiki-attachments:/var/www/dekiwiki/attachments \
-v $PWD/vol/var-www-dekiwiki-bin-cache:/var/www/dekiwiki/bin/cache \
--name $NAME \
osslab-dekiwiki \
/bin/bash
Using Save Command
# osslab-dekiwiki is image name
docker save osslab-dekiwiki > osslab-dekiwiki.tar
Using Export Command

Run the instance in detach mode

docker run -it --detach --name osslab-mig osslab-dekiwiki

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
673f45c27a8b        osslab-dekiwiki     "/bin/sh -c /startup…"   5 seconds ago       Up 4 seconds        80/tcp                           osslab-mig

Export Docker Container

docker export 673f45c27a8b > osslab-mig.tar

ls -l
-rw-r--r-- 1 root root 1143085568 Feb 27 14:21 osslab-mig.tar

Backup the volume

cd /root/osslab
docker stop osslab-dekiwiki
docker rm osslab-dekiwiki
tar czf osslab-val.tar.gz vol

Import Docker Container to the target machine

tar -c osslab-mig.tar | docker import - osslab-dekiwiki

Restore the volume

cd /root/osslab
tar xpzf osslab-val.tar.gz

Â