这是我的 DockerFile :-
FROM openjdk:10
ENV AQUILA_HOME /data/config
#USER root
#VOLUME /tmp
ADD a2i-web-1.0.0-SNAPSHOT.jar app.jar
#RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-jar","app.jar"]
Run Code Online (Sandbox Code Playgroud)
我的 jar 是 spring boot 应用程序,需要 postgres。我在本地安装了 portgres,它在我的本地主机上成功运行。我正在通过命令成功构建 DockerFile
sudo docker build -t djtijare/a2i-web:v1 .
Run Code Online (Sandbox Code Playgroud)
但是当通过命令运行它时
sudo docker run -p 8080:8080 -t djtijare/a2i-web:v1
Run Code Online (Sandbox Code Playgroud)
例外情况为:
Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Run Code Online (Sandbox Code Playgroud)
我正在从包含 DockerFile 和我的 jar 的目录运行此 docker 命令,我需要设置任何配置来运行 postgres 吗?
您无法localhost从容器访问主机上使用的服务,您必须使用主机的 IP 地址才能访问。
这是因为:默认的docker将使用bridge来为你的容器设置一个内部网络,所以当容器使用localhost时,它并不意味着主机,它意味着容器自身的网络。
如果坚持的话,一个丑陋的解决方案是使用--net=host。
接下来的事情:
sudo docker run --net=host -p 8080:8080 -t djtijare/a2i-web:v1
Run Code Online (Sandbox Code Playgroud)
然后您可以使用localhost从容器访问主机的服务。
| 归档时间: |
|
| 查看次数: |
15369 次 |
| 最近记录: |