Docker Community Forums

Share and learn in the Docker community.

Connect a normal Docker container with a swarm model service

Before I run multiple docker containers within a docker compose file, by default they are connected and can use container name to access each other. Now I deploy one of them into a swarm mode service, but cannot figure a good way to remain connection.

Some details, my container include web, redis and database. The database container name is “mysql.docker.socrates”, In previous compose solution, I can directly access database from web container by URL jdbc:mysql://mysql.docker.socrates:3306/plato .

Now I move database(mysql) into swarm mode service, but leave web and redis still in normal docker container. Is there an internal channel to access database, rather than expose mysql 3306 port to public?

I tried use create a swarm overlay network(plato-network), and try to connect it from a normal docker container, but got error:

sudo docker run --network plato-network   -it ubuntu:latest /bin/bash
docker: Error response from daemon: swarm-scoped network (plato-network) is not compatible with `docker create` or `docker run`. This network can only be used by a docker service.