我是Docker的新手
Docker版本18.03.0-ce,在RHEL 7上运行构建0520e24。
我使用Spring tutorial创建了一个简单的ReST服务。超级jar在我的Windows机器上运行正常,我可以通过浏览器访问该服务。
Dockerfile:
# fetch basic image
FROM openjdk:latest
# application placed into /opt/app
RUN mkdir -p /opt/app
WORKDIR /opt/app
# local application port
EXPOSE 8080
现在,我执行了以下步骤
1.建立图像
docker build --tag=java-rest
2.运行容器
docker run -p 18080:8080 -t -i java-rest
3.检查容器是否已启动
[root@l5341t ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
38ec56c99135 java-rest "bash" About a minute ago Up About a minute 0.0.0.0:18080->8080/tcp infallible_yalow
4.将jar文件复制到容器
docker cp /localhome/ojoqcu/code/java/gs-rest-service-0.1.0.jar 38ec56c99135:/opt/app/gs-rest-service-0.1.0.jar
5.运行容器和罐子
docker run -p 18080:8080 -t -i java-rest
root@38ec56c99135:/opt/app# ls
gs-rest-service-0.1.0.jar
root@38ec56c99135:/opt/app#
root@38ec56c99135:/opt/app#
root@38ec56c99135:/opt/app# java -jar gs-rest-service-0.1.0.jar
6.在容器上,应用程序正在运行
root@38ec56c99135:/opt/app# ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 13:43 pts/0 00:00:00 bash
root 8 1 0 13:47 pts/0 00:00:14 java -jar gs-rest-service-0.1.0.
root 54 0 0 14:16 pts/1 00:00:00 bash
root 60 54 0 14:17 pts/1 00:00:00 ps -eaf
回复:
1.从同一台机器(RHEL 7)
[root@l5341t ~]# curl http://localhost:18080
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>
[root@l5341t ~]#
[root@l5341t ~]# curl http://0.0.0.0:18080
<HTML><HEAD>
<TITLE>Network Error</TITLE>
</HEAD>
<BODY>
<FONT face="Helvetica">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width="80%">
<TR><TD>
<FONT face="Helvetica">
<big>Network Error (tcp_error)</big>
<BR>
<BR>
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
A communication error occurred: ""
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica" SIZE=2>
<BR>
For assistance, contact your network support team.
</FONT>
</TD></TR>
</TABLE>
</blockquote>
</FONT>
</BODY></HTML>
[root@l5341t ~]#
[root@l5341t ~]# curl http://l5341t:18080
<HTML><HEAD>
<TITLE>Network Error</TITLE>
</HEAD>
<BODY>
<FONT face="Helvetica">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width="80%">
<TR><TD>
<FONT face="Helvetica">
<big>Network Error (dns_unresolved_hostname)</big>
<BR>
<BR>
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
Your requested host "l5341t" could not be resolved by DNS.
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica" SIZE=2>
<BR>
For assistance, contact your network support team.
</FONT>
</TD></TR>
</TABLE>
</blockquote>
</FONT>
</BODY></HTML>
[root@l5341t ~]#
[root@l5341t ~]#
2.从我当地的Windows机器浏览器(我认为它仍然在使用Spring Boot的嵌入式服务器但不确定!)
http://l5341t:18080/
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu May 24 14:13:44 UTC 2018
There was an unexpected error (type=Not Found, status=404).
No message available
答案 0 :(得分:0)
我没有深入挖掘Spring代码(它在WIndows / Linux机器上完美运行,但不在容器中运行!)但似乎问题实际上是代码而不是Docker配置。我找到了答案here。