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
• 6,880 points
70 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,620 points

Related Questions In Docker

+1 vote
11 answers

How to run multiple commands in docker at once?

Try this: docker run image bash -c "cd ...READ MORE

answered Apr 17 in Docker by anonymous

edited Apr 17 by Kalgi 23,485 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
• 42,410 points
39 views
0 votes
1 answer
0 votes
1 answer

How do I install phantomjs with node in docker

Here is what you can try. Link for existing ...READ MORE

answered Aug 1, 2018 in Docker by Damon Salvatore
• 5,510 points
732 views
0 votes
1 answer
0 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
• 56,920 points
226 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,620 points
183 views
0 votes
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,620 points
46 views