Maarten Kieft
Maarten Kieft

Reputation: 7125

Docker volume recreates a new target path every time

I have created the following docker file

FROM resin/rpi-raspbian:jessie-20160831
.. 
RUN mkdir -p /usr/bin/asmp
COPY src /usr/bin/asmp/
VOLUME /usr/bin/asmp/data
..

The copy actions copies a directory structure like this:

data
   db.sqlite3 
web
    ...
worker
    ...

I than just start a container, using something like this:

docker run -p 8000:8000 asmp

When I do an inspect I see this:

 "Mounts": [
        {
            "Name": "30ccc87580cd85108cb4948798612630640b5564f66de848a4e2f77db8148d3a",
            "Source": "/var/lib/docker/volumes/30ccc87580cd85108cb4948798612630640b5564f66de848a4e2f77db8148d3a/_data",
            "Destination": "/sys/fs/cgroup",
            "Driver": "local",
            "Mode": "",
            "RW": true,
            "Propagation": ""
        },
        {
            "Name": "c4473031d209eb29d3f454be68325c6b1f33aa660185bf57e8abb91a56bb260e",
            "Source": "/var/lib/docker/volumes/c4473031d209eb29d3f454be68325c6b1f33aa660185bf57e8abb91a56bb260e/_data",
            "Destination": "/usr/bin/asmp/data",
            "Driver": "local",
            "Mode": "",
            "RW": true,
            "Propagation": ""
        }
    ],

When I stop the container (by killing it) and than starting it again, it creates a new volume to a different directory. So I am wondering how to handle with this situation? Am I starting/stopping the container wrong? Or should I specify the volume differently? I do know that you can specify a target path, but can I (and should I ) specify this in the docker file? I rather specify the volume settings in the docker file, since the run command is already having a lot of parameters to redirect ports and devices..

Any thoughts?

Upvotes: 3

Views: 348

Answers (1)

Bukharov Sergey
Bukharov Sergey

Reputation: 10185

You must specify volume destination when you run container. Read about volumes

docker run -p 8000:8000 --volume=<path_on_host>:/usr/bin/asmp/data asmp

Upvotes: 2

Related Questions