Reputation: 1499
here is my docker compose file
version: '2'
services:
demoui:
image: demoimage
ports:
- "80:8000"
volumes:
- ./democonfig/config.js:/usr/local/tomcat/webapps/demo-ui/config.js
- ./logs/demo-ui:/usr/local/tomcat/logs
restart: unless-stopped
This docker compose file works when I was in single node. After moving to docker swarm . It is not working. It throws the following error
ERROR: for demoui Error response from daemon: rpc error: code = 2 desc = "oci runtime error: could not synchronise with container process: not a directory"
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "compose/cli/main.py", line 63, in main
AttributeError: 'ProjectError' object has no attribute 'msg'
docker-compose returned -1
So the questions are
How to share file to swarm cluster ?
Or need to copy all file into image and run it?
Please share some documentation of docker volume with swarm.
Upvotes: 7
Views: 4014
Reputation: 429
The error you're getting is because the source files/dirs for your volumes do not exist on the swarm nodes you are launching on. Docker (and docker-compose
) has no way to copy those files over to the other hosts in the swarm.
The source files/dirs need to be present on all of the swarm nodes that you want to share the configuration files with. You're also using a context-dependent path in your compose file, which isn't going to be consistent across all the nodes. This should instead be an absolute path (i.e. /opt/config
rather than ./config
or ~/config
).
As a quick fix, you will need to copy the config files to each node in the same location (i.e. /opt or some other directory) and modify your compose file to point to this consistent location, e.g.
volumes:
- /opt/config/config.js:/usr/local/tomcat/webapps/demo-ui/config.js
- /opt/logs/demo-ui:/usr/local/tomcat/logs
Long-term, you can either sync these files manually, use a tool like lsyncd to keep them in sync automatically across nodes, place them on an NFS volume and mount that on each node, or use something like glusterfs.
Just keep in mind for your logging dir, you will likely want to ensure your log files aren't clobbering each other so you may want to keep them local or ensure the log file names are unique to each node if using shared storage.
Upvotes: 5