【发布时间】:2019-06-13 15:54:30
【问题描述】:
我想从 Docker 容器访问我的网站,但我不能。我试图实施的步骤如下。完成所有步骤后我无法访问http://localhost:8080/index 页面,我在哪里出错了?
Spring-Boot 项目名称为demo。我的部分代码:
package com.qwerty.demo.rest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class FunRestService {
@GetMapping("/index")
public String setIndex() {
return "HELLO WORLD!";
}
}
我的dockerfile 代码:
FROM openjdk:8
COPY . /usr/var/www/MYPROJECT
WORKDIR /usr/var/www/MYPROJECT
EXPOSE 8080
CMD ./mvnw spring-boot:run
我使用此命令将 Spring-Boot 项目构建到 myimage1。
docker build -t myimage1 .
然后,我使用此命令从myimage1 创建一个新容器。
docker run --name mycontainer1 myimage1
Maven 会下载必要的文件并为我启动我的应用程序。最后输出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.2.RELEASE)
2019-01-19 17:40:32.604 INFO 6 --- [ main] com.qwerty.demo.DemoApplication : Starting DemoApplication on 8086b6e010fb with PID 6 (/usr/var/www/MYPROJECT/target/classes started by root in /usr/var/www/MYPROJECT)
2019-01-19 17:40:32.613 INFO 6 --- [ main] com.qwerty.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-01-19 17:40:34.119 INFO 6 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-01-19 17:40:34.170 INFO 6 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-19 17:40:34.171 INFO 6 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-19 17:40:34.186 INFO 6 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]
2019-01-19 17:40:34.288 INFO 6 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-19 17:40:34.289 INFO 6 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1559 ms
2019-01-19 17:40:34.602 INFO 6 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-01-19 17:40:34.882 INFO 6 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''2019-01-19 17:40:34.888 INFO 6 --- [ main] com.qwerty.demo.DemoApplication : Started DemoApplication in 3.176 seconds (JVM running for 69.839)
我们应该怎么做才能将这样的 Spring-Boot 项目(使用Dockerfile)转换为图像?如何访问我的网页?
【问题讨论】:
标签: spring-boot docker dockerfile