How to deal with persistent storage e g databases in docker

0 votes

I am currently using this approach: build the image, e.g. for Postgres, and then start the container with

docker run --volumes-from c0dbc34fd631 -d app_name/postgres

IMHO, that has the drawback, that I must not ever (by accident) delete container "c0dbc34fd631".

Another idea would be to mount host volumes "-v" into the container, however, the userid within the container does not necessarily match the userid from the host, and then permissions might be messed up.

How deal with persistent storage for your docker containers?

Jul 18, 2018 in Docker by Nilesh
• 7,060 points
787 views

1 answer to this question.

0 votes

For Docker 1.9.0 and above,

Use volume API

docker volume create --name hello
docker run -d -v hello:/container/path/for/volume container_image my_command

If you create a container with a -v volume_name:/container/fs/pathdocker will automatically create a named volume for you that can:

  1. Be listed through the docker volume ls
  2. Be identified through the docker volume inspect volume_name
  3. Backed up as a normal dir
  4. Backed up as before through a --volumes-from connection

The new volume api adds a useful command that let you identify dangling volumes:

docker volume ls -f dangling=true

And then remove it through its name:

docker volume rm <volume name>

as @mpugach underlines in the comments you can get rid of all the dangling volumes with a nice one liner:

docker volume rm $(docker volume ls -f dangling=true -q)

# or using 1.13.x

docker volume prune

Hope this answer helps you.

answered Jul 18, 2018 by Kalgi
• 2,680 points

Related Questions In Docker

+2 votes
1 answer

How to link one running container with other running container in docker.

Hi @Yuvraj! Yes, this is possible. You can ...READ MORE

answered Dec 16, 2019 in Docker by Kalgi
• 52,350 points
2,228 views
+3 votes
12 answers

How to run multiple commands in docker at once?

In order to run multiple commands in ...READ MORE

answered Jul 19, 2018 in Docker by Sophie may
• 10,620 points
250,333 views
0 votes
1 answer

How to list containers in Docker

To show only running containers use the given command: docker ...READ MORE

answered Jul 20, 2018 in Docker by Kalgi
• 52,350 points
829 views
0 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,738 views
0 votes
1 answer

How to store data in external drive with Docker Postgres:9.3 image?

Apparently, the problem would be in your ...READ MORE

answered Jul 12, 2018 in Docker by Kalgi
• 2,680 points
2,648 views
+1 vote
1 answer

How to remove old Docker containers

There is a new feature in Docker 1.13.x called Docker ...READ MORE

answered Jul 18, 2018 in Docker by Kalgi
• 2,680 points
779 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP