Backup of Docker image - docker

Is it possible to keep backup of docker images?
Here is my docker image:
my#onl-dev:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centdemo latest e0b0d89f6c45 2 days ago 3.322 GB
I have some data in this docker image which I copy from container to host whenever needed.
root#onl-dev:/distros/centos6.6.x86_64# docker cp 9512b894d107:/distros/centos6.6.x86_64 /data/sept15/mess
So I want to keep backup of this docker image such that I can restore it whenever I want to copy the data from container to host.

You can simply tag the image with different tag
docker tag <image-name>:latest <image-name>:backup
Nonetheless you can always use the image ID: e0b0d89f6c45
Another option is to store it in a tar.
docker save mynewimage > /tmp/mynewimage.tar

Related

Docker image doesnt retain changed information

OK so my requirement is to modify the docker image. Following are my steps:
Pull the docker image
Run the container.
Step into the container and modified the file.
Create an image from container
Stop the container
Rerun the container with new image.
I was expecting the file i had modified should be updated, but its not. Is there anything i am missing ?
You need to delete you image docker with docker rmi <imagename> for list all images run docker images

Moving docker container to new server

I have upgraded to a new server and am trying to migrate my Docker containers over.
Most of the containers that I am running are made up of multiple image files
I used the docker commit appID appname command to create my own images of each
and then saved all of the images to a .tar file using
docker save image1 image2 image3 > backup.tar
Then transfered the tar file to my new server and ran
docker load -i backup.tar
Which added the backup images as wel as associated volumes on to my new server...
The problem I now have is, there are 7 image files and I cannot find a way to create the docker container using these image files.
When I use the YAML file and change the image to represent the locally stored image rather than the image from the docker repository, it still pulls the image from the repository
Is there a recommended way to launch the container from the local images exported from the tar file?
Maybe you can use something like this:
docker save -o backup.tar $(docker images --format "{{.Repository}}:{{.Tag}}")
Alternatively:
docker save $(docker images --format "{{.Repository}}:{{.Tag}}") > backup.tar
This will tag your images with the name and tags.
Once you do
docker load -i backup.tar
and perform:
docker images -a
you will be able to use the images based on the name:tag

How to load updated docker image onto other machine

I have 2 hosts running the same docker customized image. I have modified the image on host 1 and saved the image to a custom.tar. If I take that image and load it onto host 2 will it just update or should I remove the old docker image first?
There are 2 ways to do that with repository and without repository using load and save.
With repository below are the steps.
Log in on Docker Hub
Click on Create Repository.
Choose a name and a description for your repository and click
Create.
Log into the Docker Hub from the command line
docker login --username=yourhubusername --email=youremail#company.com
tag your image
docker tag <existing-image> <hub-user>/<repo-name>[:<tag>]
Push your image to the repository you created
docker push <hub-user>/<repo-name>:<tag>
Pull the image to host 2
docker pull <hub-user>/<repo-name>:<tag>
This will add the image to docker hub and available on internet and now you can pull this image to any system.
With this approach you can keep the same images with different tags on system. But if you don't need old images better to delete that to avoid junk.
Without docker hub.
This command will create tar bundle.
docker save [OPTIONS] IMAGE [IMAGE...]
example: docker save busybox > busybox.tar
Load an image from a tar archive or STDIN
docker load [OPTIONS]
example:docker load < busybox.tar.gz
Recommended: Docker hub or DTR approach easy to manage unless you have bandwidth issue in case your file is large.
Refer:
Docker Hub Repositories

Docker save/load lose original image repository/name/tag

I'm using Docker 1.12.6.
I have pulled an image from the Docker registry.
I have exported the images as tar files using the docker save command.
I removed the original image and container and loaded the exported image using docker load -i myImage.tar.
Now, when running docker images I notice my image have lost its repository/tag information:
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5fae4d4b9e02 8 weeks ago 581.3 MB
Why does it have this behavior and how do I keep the original image name?
Use
docker save -o filename.tar <repo>:<tag>
The command docker save <image id> removes the repository and tag names.
To solve this, use docker save <repo>:<tag> it will keep the repository and tag name in the saved file. For example:
docker save -o ubutu-18.04.tar ubuntu:18.04
I had the same problem, so I used the following command to fix it manually:
docker tag <Image-ID> <desired Name:Tag>
Reference
[NOTE]:
It's inconsistent: docker save image-repo-name -> docker load
restores name, docker save SHA -> docker load no names or tags,
docker save name:latest -> docker load no names or tags.
AND:
The current (and correct) behavior is as follows:
docker save repo
Saves all tagged images + parents in the repo, and creates a
repositories file listing the tags
docker save repo:tag
Saves tagged image + parents in repo, and creates a repositories file
listing the tag
docker save imageid
Saves image + parents, does not create repositories file. The save
relates to the image only, and tags are left out by design and left as
an exercise for the user to populate based on their own naming
convention.
Reference
A single image ID can have multiple names/tags,
so the way that you loose the the names and tags is
what I would expect to happen after saving and loading the image to/from a tar ball.
Mode details are in the discussion about it here
From docker documentation:
cat exampleimage.tgz | docker import - exampleimagelocal:new
root#mymachine:/tmp# cat myimage.tar | docker import --message "New image imported from tarball" - reponame:my-image-name
sha256:be0794427222dcb81182a59c4664b350ecb5ffb7b37928d52d72b31
root#mymachine:/tmp# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
reponame my-image-name be0794427222 6 seconds ago 4.31GB
This one worked for me.
This is a work around
Go to source docker host machine, create text file containing all the image details using the following command docker image ls > images.txt
The above command will produce a text file similar to the following
REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> 293e4ed402ba 2 weeks ago 315MB <none> <none> d8e4b0afd6ba 2 weeks ago 551MB
Make necessary edits to set the tag by using docker image tag command
docker image tag 293e4ed402ba postgres:latest
docker image tag d8e4b0afd6ba wordpress:latest
I wrote a one-line script that importing a bunch of .tar files and immediately tagging the image.
for image in $(ls); do docker tag "$(echo $(docker import $image))" $image ; done
Note, that you should be inside the folder when all the tar files are located.

Name a docker at build and how to retrieve it

I tried to build a docker image. Then on docker images command, the list displays:
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> eaaf8e203bd4 1 min ago 253.2 MB
Is there a way in my Dockerfile to specify a name for this build? Or at docker build . command line?
Another question: I want to upload via SFTP the docker container on my production server and run it. Where are the containers stored?
You should use the -t option of docker build
docker build -t name:tag
The tag is optional.
I want to upload via SFTP the docker container on my production server and run it.
You should "upload" the image, and by that I mean push it to a docker registry running on your server.
You could also commit a running container into an intermediate image (which would freeze the running state of the container, but would not preserve the volume data, if one was declared in that container)
Then copy that archive, and docker import it.
See "How to move docker containers between different hosts".
Once imported, see "Where are docker images stored on the host machine?".
(/var/lib/docker/containers for containers)

Resources