An In-Depth Exploration of Exporting and Importing Docker Containers and Images
Introduction
In my DevOps journey, I've been having a great time expanding my Docker knowledge! Today, I practised managing containers and working with images. I focused on executing commands within running containers and had fun pausing and unpausing them. I also explored the process of exporting and importing container images
Key Terminologies
Docker :-
Docker is a user-friendly open-source platform that makes it easy to deploy applications in lightweight, portable containers that can run just about anywhere. By using containerization, Docker helps simplify the software development process, making it smoother and more efficient for developers.
Docker Image :-
A Docker image is an essential tool for creating containers. It acts as a lightweight, standalone package that contains everything necessary to run your software effectively. This includes the code, a runtime environment, libraries, environment variables, and configuration files. With a Docker image, you can be confident that your application will run smoothly and consistently every time!
Container :-
A container is a powerful runtime instance of an image that expertly runs your application in an isolated environment. It confidently encapsulates all the necessary dependencies and libraries, effectively eliminating any potential conflicts between applications. This ensures that your app operates seamlessly and reliably, giving you peace of mind.
Dockerfile :-
A Dockerfile is a simple text file that contains a set of commands that Docker uses sequentially to build an image. To read more about Dockerfile, you can read this article.
✅Exporting and Importing Docker Images
- I accessed the shell of a running container with the following command:-
docker container exec -it <container_id> /bin/bash
2. Connecting with Docker Networking:-
curl <ip_address>
3. Pausing and Unpausing Containers:-
docker container pause <container_id>
docker container unpause <container_id>
- Stopping and Terminating Containers:-
docker container kill <container_id>
docker ps -a
Cleaning Up Stopped Containers:-
docker container prune -f
✅Tasks I Completed :-
Task 1: Creating a Container and Installing Tools:-
I successfully created a container and installed the tree and git utilities within it:-
1. Create a New Container:
docker container run -itd ubuntu:18.04
2. Access the Container:
docker container exec -it <container_id> /bin/bash
3: Update the System and Install Tools:
apt-get update -y
apt-get install tree git -y
Task 2: Export the Container to a .tar File:-
I successfully exported the customized container, equipped with tree and git, into a .tar file for future use:-
- Export Command:-
docker container commit <container_id> files:v1
docker save files:v1 -o my_container_backup.tar
Task 3: Importing the Image from the .tar File:-
To import the exported image back into Docker, I used the following command:
docker load -i my_container_backup.tar
Task 4: Creating a New Container from the Imported Image:-
After importing the .tar file, I created a new container using the restored image:-
docker container run -itd files:v1