How to recover volumes and data in Docker Container

How to recover volumes and data in Docker Container

In this article, we will look at how to run a Docker container using volume mount and recover data from the Docker volume when a container is crashed/exited.

In this article, we will look at how to run a Docker container using volume mount and recover data from the Docker volume when a container is crashed/exited.

Run the Docker Container With Volume Using the -v parameter

Syntax:

docker run -dit --name <containerName> -v <volumeName>:<directoryName> -p 8080:8080 --env-file <env-file.env> <dockerImageName>

Sample command volume for /opt directory:

docker run -dit --name testcontainer -v opt-vol:/opt -p 8080:8080 --env-file properties.env <dockerImageName>

-dit runs the container in detached mode. For interactive mode use -it. -p helps to expose specified ports. If port is already in use, try with other port of host to connect.

List the active Docker containers

docker ps

List the active/exited Docker containers

docker ps -a

If the above container "testcontainer" is exited, then run another container (testcontainer1) with a new volume "opt-vol-1" for /opt directory.

docker run -dit --name testcontainer1 -v opt-vol-1:/opt -p 8080:8080 --env-file properties.env <dockerImageName>

Use the docker cp command to copy the data from existing container volume "opt-vol" to currrent container /opt once the new container is up.

docker cp /var/lib/docker/volumes/opt-vol/_data/confighome/config <new-containerID-testcontainer1>:/opt/confighome/

List the Docker volume:

docker volume ls

Inspect Docker volume:

docker volume inspect <volumeName>

docker volume inspect opt-vol

Note: Fill the values in your environment in angle brackets.

docker

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub.

Docker Architecture Overview & Docker Components [For Beginners]

Docker Architecture Overview & Docker Components. This ultimate guide revolves around the underlying technologies used by Docker Containers to provide effective containerisation services to its users. It explains the entire Docker architecture and its components using intuitive diagrams.

Docker Tutorial for Beginners 8 - Build and Run C++ Applications in a Docker Container

Welcome to this on Docker Tutorial for Beginners. In this video provides an Introduction on C++ development with Docker containers. So we will see How to ship C++ Programs in Docker.

Docker: Installing Docker and Understanding basic docker commands

“Docker: Understanding Docker Architecture and Components”, The First thing we are going to do is to run the “docker run hello-world” command. This command tries to find the “hello-world” image locally and if not found, it then downloads an image from the docker hub and runs the container out of this image.

WordPress in Docker. Part 1: Dockerization

This entry-level guide will tell you why and how to Dockerize your WordPress projects.