Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: How to extract the Docker image into local system

Tags:

linux

docker

I want to extract the Docker image (from Ubuntu server) into my local system (Linux machine).

I run the following command

docker exec -it containername_or_ID /bin/bash

I am able to view image by using this command, but I am unable to get this image into my local system.

like image 333
arun kamboj Avatar asked Sep 11 '18 09:09

arun kamboj


2 Answers

In order to extract image contents without dealing with many layers, a container should be created first. If docker run was already run, use that container, otherwise create a stopped container with docker create. Then use docker export or docker cp.

id=$(docker create image:tag)
docker export $id -o image.tar
docker rm $id
like image 149
Konstantin Pelepelin Avatar answered Oct 31 '22 06:10

Konstantin Pelepelin


It depends though on what you're actually asking for. You are talking about extracting the image, but you're referring to an existing container. While jbrownwrld's answer is right in your context, if you want to extract an image, you can use docker save for that. Identify the image using:

docker image ls
mariadb                 10.3-bionic         92744546933d        4 days ago          343MB

Then output the tar file (default format):

docker save mariadb:10.3-bionic --output mariadb.tar
mkdir mariadb && mv mariadb.tar mariadb && cd mariadb && tar xvf mariadb.tar

There are lots of files and folders being extracted, so you had better use another directory. The folders generally correspond to the image layers.

like image 33
Lethargos Avatar answered Oct 31 '22 06:10

Lethargos