Cannot connect to Postgres from a SpringBoot app running in a docker container - spring-boot

I have a Spring Boot application that is running in a docker container. From this application I am trying to connect to a Postgres DB that is running in localhost.
I am getting Connection refused error.
I tried solution #1 & #3 mentioned in the below post, but that is also not working.
Using Docker to launch web app, can't connect to Postgresql DB?
What I tried so far
Spring Boot application.properties has Postgres url as localhost:5432 and
docker run --add-host [dockerhost ip] -it and docker run --net=host -it
Spring Boot application.properties has Postgres url as [dockerhost ip]:5432
and docker run --add-host [dockerhost ip] -it and docker run --net=host -it
Neither of the above is working.
I am using Docker for Mac 1.12.5

Related

Can not show tables in sequel pro while they do exist according to docker container

I'm rather new at docker and i am currently having some trouble with my new laravel project
I started a new laravel project using laravel sail, which created a mysql container called organiser_mysql_1
I am able to view my database in my docker container, but when i try to use the same credentials on sequel pro, the database does not show.
docker container:
show databases
Sequel pro:
sequel pro credentials
sequel pro error
docker ps:
docker ps
env file:
env file
database.php
database.php
Command i used to get into docker container:
docker exec -it organiser_mysql_1 mysql -uroot -p
I can log into sequel pro without the Database: organiser, but the tables in my docker container are not in there.
You're probably connecting to to a MySQL server running directly on you host machine (Mac) and not to the one running in your docker container.
To verify:
lsof -i tcp:3306
There is a good chance it shows mysqld running on your Mac
To fix:
Or stop mysqld on your Mac or choose a free port (not 3306) in the next step
Map port 3306 in your container to a port on your Mac. You do this by adding FORWARD_DB_PORT=3307 (or other port) to you .env. This works because of this line.
Restart your containers by running sail stop && sail up -d

Docker hub jhipster-registry not accessible on port 8761

I have recently started exploring the microservice architecture using jhipster and was trying to install and run the jhipster-registry from docker hub. Docker shows that the registry is running, but I am unable to access it on port 8761.
Pulled the image with docker pull jhipster/jhipster-registry
Started the container with docker run --name jhipster-registry -d jhipster/jhipster-registry
Here's a snapshot of what docker container ls returns:
Am I missing something over here?
You are starting the JHipster Registry container, but you aren't exposing the port.
You can expose a port by passing the port flag -p 8761:8761 which will enable you to connect to it via localhost:8761 or 127.0.0.1:8761 in a browser.
You may need to configure some environment variables for the JHipster Registry to start correctly. These may depend on your generated app's options, such as authentication type. For convenience JHipster apps come with a docker-compose.yml file. You can start it with docker-compose -f src/main/docker/jhipster-registry.yml up, as documented.

Getting Docker container network to run on Heroku

I am a Docker novice, but locally I can successfully run my container with: docker run -d -v /var/run/docker.sock:/var/run/docker.sock --net example-net -p 8080:8080 my/repo
Typically I can just push a container to Heroku and it just works (which I thought was the whole idea of Docker; once you get it to run once it should run everywhere), but in this case the application doesn't load.
Presumably something about the above docker run is non-standard and the Heroku Docker environment isn't running my container in the same way my local environment is.
I don't know enough about Docker or Heroku to really debug further.
The underlying application is a Spring Boot web app and Heroku logs say Web process failed to bind to $PORT within 60 seconds of launch

Failed to communicate a dockerized process with elastic search with "None of the configured nodes are available"

I have spring boot application which communicate with ElasticSearch 5.0.0 alpha 2.
My application successfully communicate with elastic and preform several queries.
When I try to dockerize my application, it fails to communicate with ElasticSearch, and I get the following error:
None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{127.0.0.1:9300}]
I have spent a lot of time on the internet, but I have found problems when the ElasticSearch is dockerized, but in my case, the client is dockerized, and it is working fine without the docker.
The command I used to create the docker image is: docker build -t my-service .
The DockerFile is:
FROM java:8
VOLUME /tmp
ADD ./build/libs/myjarfile-2.0.0.jar app.jar
EXPOSE 8090
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
To execute the image i use: docker run --name myname -d -p 8090:8090 -t my-service
Can someone share his/her experience with this issue?
Thanks
Guy Hudara
The problem is that your elasticsearch is not available on your dockerized host. When you put something in a docker container it also gets isolated on a network layer and localhost is localhost of the docker container but not the host itself. Therefore if you have elasticsearch also in a docker container use container linking and environment variable injection or reference your host machines address of your main network interface – not loopback – to your app.
Option 1
assuming that elasticsearch exposes 9200 try to run the following
$ docker run -d --name=elasticsearch elasticsearch
$ docker run -d --name=my-app --link elasticsearch:elasticsearch -p 8090:8090 my-app
Then you can define elasticsearch address in your app using env variable ${ELASTICSEARCH_PORT_9200_TCP_ADDR}.
Option 2
assuming your host machine runs on 192.168.1.10 you can also do the following:
$ docker run -d -p 9200:9200 elasticsearch
$ docker run -d -p 8090:8090 my-app
note that the name for the easticsearch container is optional here but the exposing of elasticsearch port mandatory. In this case you'll have to configure your elasticsearch host in your app given address of 192.168.1.10.

Can't access docker-machine IP on Windows

I'm using Docker Terminal on Windows running a container from my nginx image and when I access the docker-machine IP on my browser I get "CONNECTION_REFUSED".
This is command that I used to run the container
docker run -it -d -v /home/user/html:/usr/share/nginx/html -p 80:80 myimage
Check if your container is running (docker ps)
Log in your container to see if there is any error log (docker exec -it container_name /bin/bash)
Make sure you are using correct IP address (docker-machine ip container_name)
It's very important to check logs with docker logs <container name>
After that, you'll see if connection refused is due to a
Address visibility problem.
NginX configuration problem.
Port 80 is already being used.
...

Resources