Dino Geek, try to help you

How to backup and restore a Docker container?


There are several ways to backup and restore a Docker container:

1. Docker commit approach: The Docker commit command enables us to create a new image that preserves the container’s current state.

Backup: \`\`\` docker commit -p \`\`\` The -p option here is used to pause the container during the commit. Restore: \`\`\` docker run -it \`\`\` It creates a new container and starts it.

1. Docker export and import approach: The Docker export command allows us to export a container’s file system as a tar archive.

Backup: \`\`\` docker export > .tar \`\`\` Restore: \`\`\` cat .tar | docker import – \`\`\` \`\`\` docker run -it \`\`\` It creates a new container from the imported image and starts it.

1. Docker data volumes approach: This is recommended when we need to back up databases running inside a Docker container.

Creating a data volume: \`\`\` docker run -v /path/to/data-volume —name -it \`\`\` Backing up a data volume: \`\`\` docker run —rm —volumes-from -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /path/to/data-volume \`\`\` The ubuntu:14.04 image is used here to run the tar command, which creates a backup.tar file in the current directory. Restoring a data volume: \`\`\` docker run —rm -v /path/to/data-volume -v $(pwd):/backup ubuntu bash -c “cd /root && tar xvf /backup/backup.tar“ \`\`\`

1. Dockerfile approach: It’s the most efficient way to back up a Docker container if container was created based on Dockerfile.

Backup: \`\`\` docker build -t . \`\`\` Restore: \`\`\` docker run -it \`\`\` It creates a new Docker container from the Dockerfile.

Please note, in all above backup and restore process, you need to replace “” with your actual Docker container id, “” with the name you want to give to your new Docker image, “.tar” with the tar file you want to create, “” with your actual Docker container name, and “” with your actual Docker image name.

Before using the above commands, make sure Docker is installed and running in your system.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use