---
title: "How To Use Docker Save Image and Export for Sharing"
description: "Wondering how to share Docker containers and images? Learn how to run Docker save image and export commands in this tutorial!"
canonical: "https://adamtheautomator.com/docker-save-image/"
---

# How To Use Docker Save Image and Export for Sharing

> Wondering how to share Docker containers and images? Learn how to run Docker save image and export commands in this tutorial!

Source: https://adamtheautomator.com/docker-save-image/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How To Use Docker Save Image and Export for Sharing](https://adamtheautomator.com/wp-content/uploads/2021/11/How-to-Export-and-Save-Docker-Containers-and-Images-for-Sharing.jpg)

# How To Use Docker Save Image and Export for Sharing

[![](https://secure.gravatar.com/avatar/9c3cbd45c82cff94f1627c6862c2f3c7425e8c0c9fe804476fbcbad778e178cc?s=192&d=mm&r=g)Muhammed Ali](https://adamtheautomator.com/author/muhammed-ali/)5 November 20215 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Docker](/tag/docker/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Building a Base Docker Application](#building-a-base-docker-application)
*   [Exporting Docker Containers](#exporting-docker-containers)
*   [Importing Docker Containers](#importing-docker-containers)
*   [Saving Images via Docker Save Image](#saving-images-via-docker-save-image)
*   [Loading Docker Images](#loading-docker-images)
*   [Conclusion](#conclusion)

If you are new to Docker, you may be yet to discover how to share containers and images with other developers or machines. But is it possible to share containers? Yes! Let the [`docker save`](https://docs.docker.com/engine/reference/commandline/save/) image command and the [`docker export`](https://docs.docker.com/engine/reference/commandline/export/) image command do the trick!

In this tutorial, you’ll learn how to save and export containers and images for sharing by running Docker commands.

Ready? Let’s get started!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

*   [Docker Desktop or Engine](https://docs.docker.com/engine/install/) installed as version 20.10.7 is used in this tutorial.
*   Any Docker compatible operating system, Ubuntu is used in this tutorial.

Related:[How to Install and Use Docker on Ubuntu (In the Real World)](https://adamtheautomator.com/docker-ubuntu/)

## Building a Base Docker Application

Before jumping to exporting or saving Docker containers and images, you first need to build an application you’ll use for sharing purposes. You’ll build a basic arithmetic solution as a sample Docker application via a command-line environment.

1\. Create a file for your project named `Dockerfile`, and paste the code below into the newly created `Dockerfile`.

The code below performs a basic arithmetic operation that results in a value of 10.

```docker
# busybox provides Unix utilities in a single executable file, 
# which enables you to do some arithmetic.
FROM busybox
# Performs a basic arithmetic operation that results in a value of 10.
CMD echo $(((20*5)/10))
```

2\. Next, open your terminal, and run the `docker build` command below to build the application named (`arithmetic`) in the working location (`.`).

```powershell
docker build --tag arithmetic .
```

> _If you are using Linux, you may need to prepend the sudo command to avoid getting a “permission denied” error, like this: `sudo docker build --tag arithmetic`. Adding the `sudo` command elevates the command as administrator._

Related:[Troubleshooting Docker Permission Denied Problems](https://adamtheautomator.com/docker-permission-denied/)

3\. Execute the command below to run the Docker application you built (`arithmetic`). Running the Docker app also creates a container for your application automatically.

```docker
docker run arithmetic
```

![Running the Application (arithmetic)](https://adamtheautomator.com/wp-content/uploads/2021/11/image-61.png)

Running the Application (arithmetic)

## Exporting Docker Containers

Now that you have a base Docker application it’s time to cover how to export a Docker container. Building a huge application takes a long time and can be a drag if you just want to share the container with your team. So is there a quicker way to share the container? Yes!

Instead of building the application directly from a Dockerfile, export the Docker container.

1\. Run the `docker` command below to list all (`ls --all`) `containers` available on your machine. Note the `CONTAINER ID` of the container you want to share as you’ll need it to export the container in the next step.

> _Note that you can only export containers, not images._

```bash
docker container ls --all
```

![Listing all Docker Containers](https://adamtheautomator.com/wp-content/uploads/2021/11/image-62.png)

Listing all Docker Containers

2\. Next, run the command below to `export` the Docker container of your choice (`container-id`). Replace `container-id` with the container ID you noted in step one.

When exporting, you save the filesystem of the container in a _.tar_ archive (`arithmetic.tar`).

```bash
docker export container-id > arithmetic.tar
```

3\. Finally, check your project folder in your file manager, and you’ll see that a new _.tar_ archive has been created (_arithmetic.tar_). Since you’ve exported the container to a _.tar_ archive, you can now share it with anyone.

## Importing Docker Containers

Instead of exporting, perhaps you need to import a Docker container that a teammate shared with you. If so, the [`docker import`](https://docs.docker.com/engine/reference/commandline/import/) command is what you need. The `docker import` command takes the exported filesystem and converts it into an image filesystem you can run on your machine.

1\. Run the following `docker` command to `import` a container (`arithmetic.tar`) and convert it to an image. When importing, you must attach a tag (`latest`) and name the image (`put_any_name_here`), as shown below.

```docker
docker import arithmetic.tar put_any_name_here:latest
```

2\. Next, run the below command to list all existing Docker images, so you can verify if a new image exists.

```docker
docker images
```

Below, you can see that a new Docker image exists.

![Listing all Docker Images](https://adamtheautomator.com/wp-content/uploads/2021/11/image-63.png)

Listing all Docker Images

3\. Now execute the `docker run` command below to open the shell (`sh`) for the imported image. The container runs interactively and is attached to your terminal (`-i` and `-t` flags).

```bash
 docker run -i -t put_any_name_here:latest sh
```

You can tell by the prompt below (/ #), you’re now in the imported image’s shell.

![Accessing Imported Image's Shell](https://adamtheautomator.com/wp-content/uploads/2021/11/image-64.png)

Accessing Imported Image’s Shell

4\. Finally, run the command below to see if the image works as expected.

```bash
echo $(((20*5)/10))
```

If the image works, you’ll get an output of **10**, as shown below.

![Testing if the Docker Image Works ](https://adamtheautomator.com/wp-content/uploads/2021/11/echo.PNG.png)

Testing if the Docker Image Works

> _If you try running the image directly, you’ll get an error, as shown below, since the imported image is a filesystem image._

![Returning Error when Running Docker Image Directly](https://adamtheautomator.com/wp-content/uploads/2021/11/image-65.png)

Returning Error when Running Docker Image Directly

## Saving Images via Docker Save Image

Perhaps you want to save a Docker image rather than a container. If so, go with the `docker save` image command instead. Unlike the `docker export` command, the `docker save` command lets save one or more images to a tar archive directly and share it with anyone.

> _Note that you can only save and load Docker images, not containers._

1.  Run the command below to save a Docker image (arithmetic) to your preferred _.tar_ archive (`arm_image.tar`). You can now share the _.tar_ archive with other developers so they can load the image.

```bash
docker save arithmetic > arm_image.tar
```

2\. Now, run the command below to create a directory with the name of your choice (`mkdir arm`). But for this demo, the directory is named `arm`. The command then extracts the image from the _.tar_ archive (`-xf arm_image.tar`) to the new directory (`arm`).

Extracting the contents of the _.tar_ archive lets you confirm if the image you saved in the _.tar_ archive exists.

```bash
mkdir arm && tar -xf arm_image.tar -C arm
```

3\. Finally, run the `tree` command below to view the directory tree of the image you extracted in the `~/arm` directory. `tree ~/arm`

Below you can see the files and subdirectories inside the directory where you extracted the Docker image.

![Viewing Directory Tree of ~/arm Directory](https://adamtheautomator.com/wp-content/uploads/2021/11/image-66.png)

Viewing Directory Tree of ~/arm Directory

> _If you plan to share your Docker image on the Docker hub, the best option is to run the `docker save` command. Why? With the `docker save command`, you’re essentially saving the image exactly how it’s supposed to run. Also, you can only post images on the Docker hub, so definitely, the `docker export command` is not a good option._

## Loading Docker Images

Assuming you already saved an image for backup or sharing purposes, how would you load it to a machine? No worries, the [`docker load`](https://docs.docker.com/engine/reference/commandline/load/) command can help. The `docker load` command lets you load an image or repository to your machine, restoring both images and tags.

To better see how the `docker load` command works, delete all the Docker images you created previously.

1\. Run the command below to list all Docker `images` in your machine.

```bash
docker images
```

Below, you can see that there are two available images. Note each of the images’ **IMAGE ID** as you’ll delete those images in the next step.

![Noting Down Image IDs of Docker Images to Delete](https://adamtheautomator.com/wp-content/uploads/2021/11/image-67.png)

Noting Down Image IDs of Docker Images to Delete

2\. Run the below command to delete (`rm`) Docker images by the image IDs you specify. Replace `imageID1` and `imageID2` with the image IDs you noted in step one.

```bash
docker image rm imageID1 imageID2
```

3\. Now, run the `docker load` command below to load an image from a _.tar_ archive (`arm_image.tar`).

```bash
docker load < arm_image.tar
```

4\. Rerun the `docker images` command as you did in step one to list all available images in your machine. `docker images`

```bash
docker images
```

Below, you can see the newly loaded image.

![Listing All Docker Images](https://adamtheautomator.com/wp-content/uploads/2021/11/image-68.png)

Listing All Docker Images

5\. Finally, execute the command below to run and test if the image works.

```bash
docker run arithmetic
```

Notice that the command returned a value of 10, which indicates the loaded image works.

![Running the Loaded Docker Image (arithmetic)](https://adamtheautomator.com/wp-content/uploads/2021/11/image-69.png)

Running the Loaded Docker Image (arithmetic)

## Conclusion

Throughout this tutorial, you’ve learned how to export and import containers, as well as loading and saving images. You should now have a foundational knowledge of converting your Docker save images and containers into a shareable form, such as a TAR file.

At some point, you’ll need to share your Docker image or container. Now how do you plan to incorporate this newfound knowledge when working with Docker containers and images, perhaps a backup system?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fdocker-save-image%2F&text=How%20To%20Use%20Docker%20Save%20Image%20and%20Export%20for%20Sharing)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fdocker-save-image%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fdocker-save-image%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/12/buildah.jpg)

### [Building OCI Images with Buildah](/buildah/)

Master the art of crafting OCI images with buildah for seamless containerization—flexible, efficient, and tailored to your container needs.

![](https://adamtheautomator.com/wp-content/uploads/2023/06/docker-raspberry-pi.jpg)

### [How to Install Docker on Raspberry Pi 4](/docker-on-raspberry-pi/)

Excerpt: Learn how to get started with installing Docker on Raspberry Pi 4 and offload development to a small flexible system.

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Getting-Started-with-Docker-Rancher-Desktop.jpg)

### [Getting Started with Docker Rancher Desktop](/docker-rancher/)

Learn how to get started with the Docker Desktop alternative, Docker Rancher Desktop in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
