這個是我將jar包封裝成docker所用的Dockerfile 檔案
# 基于jdk鏡像
FROM java:8
# 將本地檔案夾掛在到當前容器
VOLUME /tmp
# 復制檔案到容器
ADD boss-bes-system-manager-controller-0.0.1-SNAPSHOT.jar app.jar
# 宣告需要暴露的埠
EXPOSE 8081
# 配置容器啟動后執行的命令
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
然后執行以下命令構建鏡像以及啟動容器
docker build -t systen-manager .
docker run -d --name system-service --expose=8081 -p 8081:8081 -e "EUREKA_INSTANCE_IP-ADDRESS=.。。。。。" -e "SERVER_PORT=8081" system-manager
這是打開后的容器

這是postman的報錯
{
"timestamp": "2020-04-11T13:28:31.239+0000",
"status": 500,
"error": "Internal Server Error",
"message": "nested exception is org.apache.ibatis.exceptions.PersistenceException: \n### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\n### The error may exist in class path resource [mappers/UserMapper.xml]\n### The error may involve com.boss.bes.system.manager.dao.mapper.UserMapper.selectByCode\n### The error occurred while executing a query\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.",
"path": "//system/user/findUserByCode"
}
uj5u.com熱心網友回復:
資料庫本地運行jar能連接上,但是jar封裝成docker后無法連接到資料庫。可以查一下資料庫是否可以通過這種鏡像方式連接。可以嘗試給資料庫配置一個鏡像然后通過鏡像地址和埠來連接資料庫。uj5u.com熱心網友回復:
資料庫連接不上,確定你的資料庫是不是和你的容器是否在一個網段轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/94593.html
標籤:Java EE
上一篇:公眾號呼叫視頻受限
