My situation is I have my main service on container A and another helper service on container B. Container B is the sidecar of container A so I need container B will be deployed on the same Swarm node with container A.
How can I achieve this requirement?
I’m using a docker-compose.yml file to deploys my services, so it would be helpful if someone can give me an example with a docker-compose file.
The lagacy standalone Swarm did support affinity using env variables. The build in Swarm-mode does not. If you desperatly need affinity, use the davideshay’s workaround in the linked post or switch to a container orchestrator which actualy supports affinity like Kubernetes.