2

I met some problems with micro-spring-docker , i think maybe the sso token-url is not correct.

The demo https://github.com/keryhu/micro-oauth2-docker

In local computer , sso service and auth-service works fine .

But not in docker container ,

the problem is that redirecting to auth-server Timeout .

SSO(pc-gateway service) application.yml:

security:
  user:
    password: none
  oauth2:
    client:
      accessTokenUri: http://${AUTHSERVER_PORT_9999_TCP_ADDR:localhost}:9999/uaa/oauth/token
      userAuthorizationUri: http://${AUTHSERVER_PORT_9999_TCP_ADDR:localhost}:9999/uaa/oauth/authorize

docker-compose.yml

eureka:
  image: eureka:0.0.1-SNAPSHOT
  container_name: eureka
  hostname: eureka
  ports:
   - "8761:8761"

configserver:
  image: config-server:0.0.1-SNAPSHOT
  container_name: configserver
  hostname: configserver
  links:
    - eureka
  ports:
    - "8888:8888"

authserver:
  image: auth-server:0.0.1-SNAPSHOT
  container_name: authserver
  hostname: authserver
  links:
    - eureka
    - configserver
  ports:
    - "9999:9999"

pcgateway:
  image: pc-gateway:0.0.1-SNAPSHOT
  container_name: pcgateway
  hostname: pcgateway
  links:
    - eureka
    - configserver
    - authserver
  ports:
    - "8080:8080"

After starting in docker container :

http://192.168.99.100:8761/ showing :

Instances currently registered with Eureka
Application   AMIs     Availability Zones   Status
AUTHSERVER   n/a(1)           (1)           UP (1) - authserver:authserver:9999
CONFIGSERVER n/a(1)           (1)           UP (1) - configserver:configserver:8888
PCGATEWAY    n/a(1)           (1)           UP (1) - pcgateway:pcgateway:8080

But when open the auth page: http://192.168.99.100:8080

It should be redirected to auth-server login page , but it opened Timeout , the Address Bar is:

http://172.17.0.4:9999/uaa/oauth/authorize?client_id=clientapp&redirect_uri=http://192.168.99.100:8080/login&response_type=code&state=cdXhfg

I don't know why , maybe the above sso tokenurl is not correct . How to resolve ?

Kery Hu
  • 5,626
  • 11
  • 34
  • 51

1 Answers1

3

The 172.17.0.4 IP-address is the IP-address of the authserver container on the internal (container-container) network, which is not reachable from outside the docker host (Virtual Machine).

This may be tricky, because (in this case) you need to provide the IP-address of the Virtual Machine that docker runs on, which may change, and definitely will be different in production.

If you change ${AUTHSERVER_PORT_9999_TCP_ADDR:localhost} to 192.168.99.100, it should work.

I suggest to make the IP-address (or domain) configurable using an environment-variable that you provide in the docker-compose.yml, so something like:

${DOMAIN_NAME:192.168.99.100}

Which defaults to the "standard" IP-address of the Virtual Machine. In production you can then pass the actual domain-name, or IP-address of the server your project runs on.

Note that the "link" environment variables are marked deprecated, and only will be used on the default (bridge) network. The new linking feature won't create these variables, but you can simply link to other containers by name. See https://docs.docker.com/engine/userguide/networking/work-with-networks/#linking-containers-in-user-defined-networks

thaJeztah
  • 27,738
  • 9
  • 73
  • 92
  • sorry , I'm a newer. I have not resolved completely . I write: `domainname: 192.168.99.100` in docker-compose.yml by a line , in spring application.yml write `http://${domainname:localhost}:9999/uaa/oauth/token` ? – Kery Hu Feb 19 '16 at 10:54
  • you can start with changing your config to `accessTokenUri: http://192.168.99.100:9999/uaa/oauth/token` to see if that works, and work from that (the environment variables solution) see environment variables in the docker-compose documentation; https://docs.docker.com/compose/compose-file/#environment – thaJeztah Feb 19 '16 at 10:58
  • 1
    thanks,it works ,i write environment: `DOMAIN_NAME: 192.168.99.100` in docker-compose.yml ,and `http://${domain.name:localhost}:9999/uaa` in application.yml – Kery Hu Feb 19 '16 at 11:26