I’m using a
docker-compose.yml file along with
docker stack deploy to deploy a web service, a database service and some other supporting services across a cluster. This all works as expected.
The only piece I can’t work out is how to handle one off commands.
For example, I want to run the command
bundle exec rake db:migrate within a web service container. That container needs to have access to the database server via it’s hostname. When using compose locally, it’s easy I can just use:
docker-compose run SERVICE_NAME CMD
But I can’t work out a way to do this on swarm. I’ve tried:
docker run -it --network=dcdeploydemo_default 127.0.0.1:5000/dcdeploydemo:1.1 bundle exec rake db:migrate
But the hostname doesn’t resolve.
Similarly I want to be able to run bash in one of these containers and attach to it. What’s the current correct way of approaching this when using swarm?