Mike Nöthiger
1 min readMay 26, 2020

--

Hi Markus, if I get it right, you’re deploying a spring container to your server, but spring can not connect to the database which runs on the same server?

If that is your problem, here are two suggestions.

You could use docker networks to connect both, the spring and database container. That would look somehow like:

docker network create your_network
# start the myql container
docker run --network your_network --name your_db mysql
# start the spring container (you probably have this in your pipeline)
docker run --network your_network spring-app

Containers in the same network can talk to each other using the container name as hostname. So the database should be reachable as your_db:3306 (or whatever port your DB is using) from your spring container. You’d have to specifiy that DB hostname somewhere in your spring app (that is usually in the application.properties for spring applications).

Alternatively you could publish your database container on a server port:

# publish mysql container on your_server_ip:3306
docker run -p 3306:3306 mysql

Now your spring application should reach the database on your_server_ip:3306. This requires that 3306 of your server is not protected by a firewall.

Personally I’d take the first approach, because it isolates the database from the public and makes it only available to your spring container.

Let me know if that didn’t work for you.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Mike Nöthiger
Mike Nöthiger

Written by Mike Nöthiger

Hi! 👋 I’m Mike — did you know the oldest computer was owned by Adam and Eve? It was an apple with very limited memory. Just one byte and everything crashed.

No responses yet

Write a response