容器是从docker-compose 3.9创建的,如下所示:
version: '3.9'
services:
mongo:
image: mongo:4.4.15
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
ports:
- "27017:27017"
tty: true
stdin_open: true
volumes:
- mongo-vol:/docker-entrypoint-initdb.d/
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
start_period: 40s
mysql:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: 'mydb'
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ROOT_PASSWORD: 'password'
volumes:
- mysql-vol:/docker-entrypoint-initdb.d/
healthcheck:
test: /usr/bin/mysql mysql -ppassword --silent --execute "select 1"
interval: 10s
timeout: 10s
retries: 5
my-be:
image: be_image
container_name: be-container
ports:
- "8080:8080"
environment:
spring.datasource.url: "jdbc:mysql://mysql:3306/mydb?allowPublicKeyRetrieval=true&useSSL=false&createDatabaseIfNotExist=true"
datasource.driver-class-name: "com.mysql.cj.jdbc.Driver"
spring.h2.console.enabled: "false"
spring.jpa.database-platform: "org.hibernate.dialect.MySQLDialect"
spring.data.mongodb.host: mongo
spring.data.mongodb.port: 27017
logging.file.path: logs
server.port: 8080
depends_on:
mongo:
condition: service_healthy
mysql:
condition: service_healthy
volumes:
mysql-vol:
mongo-vol:
我正在创建一个后端容器,一个mysql和一个mongo。
停靠文件:
FROM openjdk:17
EXPOSE 8080
ARG JAR_FILE="target/MyAPP-0.0.1-SNAPSHOT.jar"
ADD ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
我创建了BE的构建映像,并在docker-compose中使用它。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
996da02a43e5 be_image "java -jar /app.jar" 11 minutes ago Up 11 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp be-container
9c3d11ceb0ee mongo:4.4.15 "docker-entrypoint.s…" 11 minutes ago Up 11 minutes (healthy) 0.0.0.0:27017->27017/tcp, :::27017->27017/tcp compose-mongo-1
15fe4d52a50e mysql "docker-entrypoint.s…" 11 minutes ago Up 11 minutes (healthy) 3306/tcp, 33060/tcp compose-mysql-1
我使用的是Spring security。所以当我尝试输入localhost:8080时,它会提示输入用户名和密码。当我输入它们时,一切似乎都运行正常,显示通常的Whitelabel错误页面。但是,如果我尝试检索swagger-io,它会给我一个空的swagger(而没有docker,它工作正常)。而且,如果我尝试调用POST或任何来自POSTMAN的调用(甚至只调用localhost:8080),它会返回401 unauthorized,而不会在spring Boot 应用程序中记录任何内容。最后一个日志是
2023-03-14T14:11:07.344Z INFO 1 --- [ main] com.example.myapp.MyApplication : Started MyApplication in 3.978 seconds (process running for 4.521)
在到达tomcat之前似乎有一个阻塞,如果我尝试调用https而不是http,我实际上在spring Boot 中有一个日志:
2023-03-14T14:13:36.511Z INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-03-14T14:13:36.513Z INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms
2023-03-14T14:14:02.018Z INFO 1 --- [nio-8080-exec-3] o.springdoc.api.AbstractOpenApiResource : Init duration for springdoc-openapi is: 99 ms
2023-03-14T14:34:55.564Z INFO 1 --- [nio-8080-exec-7] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x000xf70x010x000x000xf30x030x03z0xfe0x90q0xe80x0an0x960xd50xcc0xb80x93lv0xfcf0xfc0xf50xdeT0x980xfa0xd6?0x99^0xe70x940x900xcaoP ]. HTTP method names must be tokens
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:419) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:272) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1739) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-10.1.1.jar!/:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-10.1.1.jar!/:na]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
看起来有些东西被记录下来了。我不知道我错过了什么,我知道我就快成功了。
如果不进行停靠,本地一切正常
1条答案
按热度按时间wsewodh21#
您是否使用SSL?如果您尝试使用https访问端点,但您的服务器不支持它,您可能会收到如下所示的错误。