I tried to restart Postgres in Docker using 'docker restart ' command. It got stopped but I'm not able to start it. When I run the command 'ps -a' it says the status as 'Exited'. Is there any way to start it again? I don't want to loose any data in that database.
The container had one active connection during restarting. Is that creating a problem?
1 Answer
If the container crashed due to a bug or something, you may not be able to restart it. However, you should still be able to recover at least part of your data by making a new image out of the container that you want to recover. Here's how you do it:
First, list all the containers that have run in your machine:
docker ps -aFind out which one is the container that run with all the data you want to recover. You should be able to figure out from the
CREATEDfield (you know when you started it).Grab the hash (
CONTAINER_ID) of the container, and execute the following command:docker commit <hash> <a_new_name:tag>This will save the container as an image that you can execute.
Execute the container with a
bashorshsession, depending on what our base image offers:docker run --entrypoint sh/bash -it <a_new_name:tag>
This will give you access to the state of the container at the time of exiting, which will allow you to inspect its conditions, find bugs, and possibly recover some data. Good luck!
3 Comments
docker inspect <container> to see whether a volume was there. If you are using the official postgres image, you will definitely have a volume for your /var/lib/pgsql folder.
docker logs <container_id>? What is the exit code?