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.
Docker 1.13 introduced a new version of Docker Compose. The main feature of this release is that it allow services defined using Docker Compose files to be directly deployed to Docker Engine enabled with Swarm mode. This enables simplified deployment of multi-container application on multi-host.
Docker Compose is used for configuring and starting multiple Docker containers on the same host–so you don't have to start each container separately. Docker swarm is a container orchestration tool that allows you to run and connect containers on multiple hosts.
For containers to communicate with other, they need to be part of the same “network”. Docker creates a virtual network called bridge by default, and connects your containers to it. In the network, containers are assigned an IP address, which they can use to address each other.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With