I would like to use a volume with a docker swarm node so I would like to translate this no-swarm command that uses volume:
docker run --name dev_db -v /tmp/postgres:/var/lib/postgresql/data -d postgres
to this swarm command:
docker service create —-mount 'type=bind,src=/tmp/postgres,dst=/var/lib/postgresql/data,readonly' -—name dev -d -e contraint:node==/swarm1/ postgres
Error response from daemon: rpc error: code = InvalidArgument desc = ContainerSpec: "—-mount" is not a valid repository/tag
The problem is that I think that AFAIK maybe I'm wrong but swarm doesn't accept volumes so that's why I came up with this --mount
command but it's not accepting it either. Any help is appreciated.
Mount volumes is indeed supported in Swarm so I think the issue is just a typo in your command "—-mount" should be "--mount". Also I think you have another typo, contraint should be constraint and I don't think that constraint should work. If you want to use a specific node use for example node.hostname == nodename, and have a look on the examples in Docker docs. Also I think -e should be removed as you're not using environment variables.
Try with:
docker service create --mount 'type=bind,src=/tmp/postgres,dst=/var/lib/postgresql/data,readonly' --name dev -d --constraint 'node==/swarm1/' postgres