Updated March 30, 2023
Introduction to Docker Backup
In the docker environment, we are having the functionality to take the backup of the images. There are different ways to do the backup of the docker images or the docker container. While taking the backup, we need to make sure which backup we are taking, like the images backup or the data or volume backup. If we are using the commit utility to backup the container, then it will take the backup of the container. It will backup it will hold the backup like an entry point, labels, command, environment variables, etc. But the backup will be happening on the local machine level only. Once the backup will be complete, it will store on the local image. If we need to copy or move the backup image to the docker hub, we need to use the docker push utility.
Syntax
Given below is the syntax mentioned:
docker commit [ OPTIONS ] CONTAINER NAME | ID [ REPOSITORY [ : TAG ] ]
- docker: We can use the docker keyword in the syntax or command. It will accept different arguments like commit, repository name, different types of options, container name or the id, different tag, etc. As per the provided input, the docker commit command will be able to take the backup for the provided container id.
- commit: The commit is the keyword that we need to use with the docker command. It will help to run the command to the backup of the container.
- OPTION: As per the requirement, we can provide the different flags as the option that is compatible with the docker commit command.
- CONTAINER NAME or ID: In the commit command, we can define the container name or ID details. So, it will identify the container name and help to take the backup of the container. As per need, we can define the format of the backup file also.
- REPOSITORY: As per the requirement, if we need to send the images to the docker hub repositories, we need to define the repository’s path.
- TAG: As per the requirement or the need, we can also use the TAG in the docker commit command.
How Docker Backup Works?
In the docker ecosystem, the backup plays a very important role. It will be more important while we are doing some testing or the development work; we need to store the data on the container level. If the data will not store on the container, it will be more difficult to work on the container level because we need to add or load the data every time. To overcome this condition, we are having the docker commit utility.
The docker commit command will use the docker container id or the container name to backup the container. Similarly, it will accept the different options with the docker commit command like different types of options, repository path, different tags, etc. While doing the backup of the container, it will identify the docker container; it will help to save the state of the container in the same container or the file or the docker repository. As per our requirement, we need to choose which type of backup we need or where we need to store it (like on the remote location or the local docker environment).
Below is the list of options available that would be used with the exec command:
Sr. No | Option Name | Shorthand | Default Value |
Description |
1 | –author | We are using the shorthand value or option as -a. | The default value for the –author option is false. | It will help to define the author option in the docker command. For example, Hannibal John Smith < [email protected] >. |
2 | –change | We are using the shorthand value or option as -c. | The default value for the –change option is false. | The –change option will help to apply the docker file instruction. It will be in use while we are creating the docker image. |
3 | –message | We are using the shorthand value or option as -m. | The default value for the –message option is false. | We can use the –message option in the docker image. It will help to define the commit message in the docker. |
4 | –pause | We are using the shorthand value or option as -p. | The default value for the –pause option is true. | The –pause option is very helpful while we are working with the commit option in the docker. It will help to pause the container during the docker commit option. |
Examples of Docker Backup
Different examples are mentioned below:
Example #1
Creating the backup of the docker container.
In the docker environment, we are creating the docker container backup.
Code:
docker commit 8bc5ff47b4db centos:ver1
Explanation:
- As per the above command, we are doing the docker container “8bc5ff47b4db” backup.
Output:
Example #2
Creating the backup of the docker container with new configuration.
In the docker environment, we are able to do the backup with new configuration.
Code:
docker commit --change "ENV DEBUG=true" 8bc5ff47b4db centos:ver2
Explanation:
- As per the above command, we are doing the backup with the “ENV DEBUG” value.
Output:
Example #3
Creating the backup with command and expose option.
In docker, we are able to take the backup with command as well as expose option also.
Code:
docker commit --change='CMD ["apachectl"]' -c "EXPOSE 90" 8bc5ff47b4db centos:ver3
Explanation:
- As per the above command, we are doing the container backup with the command and expose option.
Output:
Conclusion
We have seen the uncut concept of the “docker backup” with the proper example, explanation and command with different outputs. We can take the backup of the container. We need to make a separate backup of the container volume if it is attached externally.
Recommended Articles
This is a guide to Docker Backup. Here we discuss the introduction, how docker backup works? and examples for better understanding. You may also have a look at the following articles to learn more –