3

I am running postgres and keycloak images on my local machine. Both of this images have exposed ports configured. But docker machine only exposing ports via TCP. So I was able to connect to the postgres via TCP, but was not able to connect to the keycloack's localhost:8080 via HTTP.

So is it possible to connect to the docker exposed ports via HTTP.

docker-compose.yml

postgres:
image: postgres:9.6.3
volumes:
    - ./db/init:/docker-entrypoint-initdb.d
environment:
    - POSTGRES_USER=root
    - POSTGRES_PASSWORD=root
ports:
    - 5432:5432

keycloak:
image: jboss/keycloak-postgres
environment:
    - KEYCLOAK_LOGLEVEL=DEBUG
    - POSTGRES_DATABASE=user-service
    - POSTGRES_USER=root
    - POSTGRES_PASSWORD=root
links:
    - postgres:postgres
ports:
    - "8080:8080"
    - "9999:9990"
    - "443:8443"
volumes:
    - ./data:/data

docker ps

2 Answers 2

3

HTTP is a protocol that rides on top of TCP, so if Docker exposes a port via TCP (as opposed to UDP, the other option), then you can connect to that port over HTTP, provided something that speaks HTTP is listening on that port inside the container.

So if you can't connect to http://localhost:8080 with the above compose file, that probably means that the keycloak service either doesn't have anything listening on port 8080 inside the container, or whatever's listening doesn't speak HTTP, or whatever's listening and speaks HTTP is refusing the connection for some other reason.

To completely rule out that the problem is with the port mapping or something on the host, hop inside the container (using docker exec) and try to connect to 8080 from inside; if you can't, then you've confirmed the problem is with whatever's running inside the container, not with anything Docker-related.

1
  • Thank you for answer. I was able to connect to the 8080 from inside the container. Also I am able to connect to it using docker machine IP i.e. 192.168.99.100:8080 but not localhost:8080...So i guess the issue is in the ports exposing/redirecting. May 20, 2017 at 10:25
0

It appears that port exposing is about connecting to the docker machine via http://{docker-machine-ip}:{port} and to be able to connect to it with localhost one need to configure ports forwarding within Virtual machine.

Local virtual machine ports forwarding

After this configuration I was able to connect to all my running containers with http://localhost:{port}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.