【发布时间】:2018-11-03 19:42:50
【问题描述】:
我是 Docker 新手
Docker 版本 18.03.0-ce,构建 0520e24 在 RHEL 7 上运行。
我使用Spring tutorial 创建了一个简单的 ReST 服务。 uber 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.运行容器和jar
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
【问题讨论】:
-
2. docker with Spring 有响应,但是说你没有配置任何/路径。也许示例 REST 有一个 @RequestMapping("/greeting") ,所以您应该调用 l5341t:18080/greeting 。相反,您不应该从本地 RHEL 7 机器连接到 8080 而不是 18080?
标签: docker