【问题标题】:spring sso with docker images带有 docker 图像的 spring sso
【发布时间】:2019-07-04 01:59:14
【问题描述】:

我正在关注this tutorial,它运行良好,它是单点登录应用程序,然后我尝试为每个服务构建一个 docker 映像并公开它们正在使用的端口,但是当我登录 app1 服务时,这个响应:

    Whitelabel Error Page
    This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Sun Feb 10 11:11:54 GMT 2019
    There was an unexpected error (type=Unauthorized, status=401).
    Authentication Failed: Could not obtain access token

也许两个 docker 镜像没有相互通信,因为如果我在没有 docker 的情况下启动这个 spring-boot 应用程序,它们可以正常工作。

that codes 中只有我引入了一个 mvn 插件来为每个项目(sso-server,app1,app2)构建一个 docker 镜像:

                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>1.4.0</version>
                    <configuration>
                        <repository>MYREPO/project</repository>
                        <tag>${project.version}</tag>
                        <buildArgs>
                            <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
                        </buildArgs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default</id>
                            <phase>install</phase>
                            <goals>
                                <goal>build</goal>
                                <goal>push</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

我尝试为每个图像命名(-n)并链接每个图像(--link),但它不起作用。

一些建议?

【问题讨论】:

  • 你试过 docker-compose 吗?
  • 你能和我们分享你的 application.yml 吗?

标签: spring spring-boot docker


【解决方案1】:

application.yml 文件中的所有 URI 都定义为转到 localhost。如果要将一个容器转到另一个容器,可以使用主机的 IP 地址或 docker 网桥地址(默认地址为172.17.0.1)。

【讨论】:

  • 你可以通过包含一些关于如何做的解释来完成你的答案
  • 我明白了,但是两张图片都必须有这个地址?或者我可以为每个定义一个 IP 地址?我正在尝试在没有 docker compose 的情况下执行此操作,因为第二部分是添加 kubernetes
  • 将应用程序的application.yml文件中的localhost替换为主机IP地址或172.17.0.1可能会解决您的问题。
  • 有效!谢谢@aburakc。现在我的目标是为每个图像创建一个 kubernetes-pod,我需要更改这个 IP 地址吗?还是我必须为每个 pod 指定一个 IP?
猜你喜欢
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 2016-07-06
  • 1970-01-01
  • 2022-12-08
  • 2017-12-21
  • 2020-08-05
  • 2020-03-09
相关资源
最近更新 更多