Docker: port 0.0.0.0:4500->9090/tcp -- What is my host url? - spring-boot

Edit: Solved. It should be
services:
web:
ports:
- "4500:4500" # intead of "4500:9090"
Anyone know which url should I type to get the website deployment? The MySql server which is jdbc:mysql://192.168.99.100:3306/- it works fine.
But the web, tried 192.168.99.100:9090/category/all, 192.168.99.100:4500/category/all localhost:4500/actuator, localhost:9090/actuator, nothing works.
Edit: After use curl from Nightt advice

Related

How to connect to my local machine domain from docker container?

I have local server with domain mydomain.com it is just alias to localhost:80
And I want to allow make requests to mydomain.com from my running docker-container.
When I'm trying to request to it I see
cURL error 7: Failed to connect to mydomain.com port 80: Connection refused
My docker-compose.yml
version: '3.8'
services:
nginx:
container_name: project-nginx
image: nginx:1.23.1-alpine
volumes:
- ./docker/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf
- ./src:/app
ports:
- ${NGINX_PORT:-81}:80
depends_on:
- project
server:
container_name: project
build:
context: ./
environment:
NODE_MODE: service
APP_ENV: local
APP_DEBUG: 1
ALLOWED_ORIGINS: ${ALLOWED_ORIGINS:-null}
volumes:
- ./src:/app
I'm using docker desktop for Windows
What can I do?
I've tried to add
network_mode: "host"
but it ruins my docker-compose startup
When I'm trying to send request to host.docker.internal I see this:
The requested URL was not found on this server. If you entered
the URL manually please check your spelling and try again.
The host network is not supported on Windows. If you are using Linux containers on Windows, make sure you have switched to Linux containers on Docker Desktop. That uses WSL2, so you should be able to use that in there.

supabase cannot connect to database

I've done a fresh install of Supabase via docker compose following this example into my Ubuntu 20.04 server. When I run docker-compose up everything works except I see this error in my logs:
supabase-rest | 21/Feb/2022:19:50:29 +0000: {"details":"could not translate host name \"l#db\" to address: Name does not resolve\n","code":"","message":"Database connection error. Retrying the connection."}
How do I fix this?
Looking at this section in the docker-compose.yml:
rest:
container_name: supabase-rest
image: postgrest/postgrest:v9.0.0
depends_on:
- db
restart: unless-stopped
environment:
PGRST_DB_URI: postgres://postgres:${POSTGRES_PASSWORD}#db:5432/postgres
It's possible that the password you used in .env is not being escaped correctly - does it contain special chars?
Note that they need to be URI encoded if so as per: How to handle special characters in the password of a Postgresql URL connection string?

Laravel Sail Share gives 404 or ERR_CONNECTION_REFUSED

Trying to use the Sail Share command with Laravel Sail, but it's not working. I've tried removing the beyondcodegmbh/expose-server image as recommended here.
It installs and everything seems to be working fine. I can get to the expose dashboard where you can follow the requests, but trying to use the expose http url without the port gives me a 404, and the url with the port just spins forever and never does anything. If I click the https link that comes up in the CLI I get ERR_CONNECTION_REFUSED.
I'm using WSL2 with Ubuntu 20.04. Sail 8.1. Docker version 20.10.12, build e91ed57.
My use case is that I'm trying to interact with an external API while doing my local development, and the API requires an HTTPS redirect url, so obviously I have to have SSL and the ability to expose the URL.
If there's another way to accomplish this without using expose, please let me know. Currently also looking into using Caddy, based on some other resources I've found.
UPDATE
I've tried changing my docker-compose.yml file with the following:
expose:
image: beyondcodegmbh/expose-server:latest
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- '${APP_PORT:-80}:80'
environment:
port: ${APP_PORT}
domain: ${APP_URL}
username: 'admin'
password: 'admin'
restart: always
volumes:
- ./database/expose.db:/root/.expose
which I got from this link, but it's still not working. I'm using port 80 in the APP_URL in my .env file, and then I put 8080 for the expose port, I'm not sure if that's right.
As of right now, it appears to be a known limitation.
The https links generated from sail share do not work.
See this ticket

Connection refused to localhost:5432 through Docker Compose after already specifying the name of the service instead of localhost

I have a few microservices running under Docker. They are Zuul, Eureka, and a configuration server. These are working but when I start my authorization-service, it says I cannot connect to PostgreSQL.
version: '3'
services:
eureka-discovery:
...
zuul-gateway:
...
config:
...
postgres:
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
POSTGRES_DB: spring_microservices
ports:
- 5432:5432
authorization-service:
image: authorization-service:0.0.1
environment:
- eureka.client.serviceUrl.defaultZone=http://eureka-discovery:8761/eureka
- spring.cloud.config.uri=http://zuul-gateway:8765/config-service
- spring.datasource.url=jdbc:postgresql://postgres:5432/spring_microservices
depends_on:
- eureka-discovery
- zuul-gateway
- config
- postgres
ports:
- 1001:1001
What's confusing is that I am specifying postgres instead of localhost to make the connection, but the error continues to say "localhost". You see I override other properties the same way I do with spring.datasource.url and they work but this one.
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
I attempted a few variations I could find around, such as using a different service name, using SPRING_DATASOURCE_URL, using the connection string as postgresql://[user]:[pass]#[service]/[database], I tried moving this line to the config-service instead since the database connection is indeed in the Spring Cloud Config Server microservice, but all to no avail. What's missing? It seems to be correct comparing to all the solutions I found.
I made Spring Config Server see my repository for the configurations. Thinking better, if it's reading from the repository it's evident that changing it on the fly locally won't work, so I updated the connection string of the configuration file for authorization-service then pushed, and it worked. I wonder if this is a good practice or better to make Config Server see local files and change it on the fly?
Hi i hope you are okay !
above your authorization-service add a link like this:
links:
- "postgres"
Greetings

Make a request to a spring api running in a docker container from windows host

So, I searched around for an answer on this matter but either people don't address the issue or they say there's no problem doing this on their computer (mac or linux). It seems like this might be a windows problem.
I have a spring api running on a docker container (linux container). I use docker desktop on windows and I'm trying to make a request (in insomnia/postman/wtv) to that api.
If I run the api locally making the following request works perfectly:
http://localhost:8080/api/task/
This will list multiples task elements.
I've containerized this application like so:
Dockerfile
FROM openjdk:11.0.7
COPY ./target/spring-api-0.0.1-SNAPSHOT.jar /usr/app/
WORKDIR /usr/app
RUN sh -c 'touch spring-api-0.0.1-SNAPSHOT.jar'
ENTRYPOINT ["java", "-jar", "spring-api-0.0.1-SNAPSHOT.jar"]
docker-compose.yml
version: '3.8'
services:
api:
build: .
depends_on:
- mysql
environment:
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/test?createDatabaseIfNotExist=true
ports:
- "8080:80"
mysql:
image: mysql
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=test
If I do docker-compose up this works without issue:
The problem is, if I try to call the same endpoint as before from localhost I don't get any response.
Insomnia returns an error saying: Error: Server returned nothing (no headers, no data)
I've also tried connecting to the container's ip (got it from docker inspect) but no luck.
Ports are exposed in docker-compose.yml. What am I missing?
Thanks in advance.
Port mapping is incorrect.Spring boot application started at 8080 (from the image I see) inside container and it should be mapped to 8080 inside the container.
It should be like below:
ports:
- "8080:8080"

Resources