我正在尝试对我的Spring Boot应用程序进行dockerize。
这是我的docker作曲文件
version: '3.8'
services:
mysql:
image: mysql:latest
ports:
- 3306:3306
hostname: mysql
environment:
MYSQL_DATABASE: ######
MYSQL_ROOT_PASSWORD: ######
MYSQL_USER: ######
MYSQL_PASSWORD: ######
volumes:
- ./mysqldata:/var/lib/mysql
backend:
build:
context: .
dockerfile: dockerfile
ports:
- 8080:8080
depends_on:
- mysql
我的dockerfile
FROM maven:3.8.4-eclipse-temurin-17-alpine AS maven
RUN mkdir -p /build
COPY pom.xml /build
COPY src /build/src
WORKDIR /build
RUN mvn -B dependency:resolve dependency:resolve-plugins
RUN mvn -DskipTests clean package
FROM tomcat:jdk8-corretto
EXPOSE 8080
RUN rm -rf /usr/local/tomcat/webapps/ROOT
COPY --from=maven /build/target/promogen.war /usr/local/tomcat/webapps/ROOT.war
CMD ["catalina.sh","run"]
我可以看到我的战争已经展开。在日志中我可以看到
2021 15:10:57.180 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
在/usr/local/tomcat/webapps目录中,我可以看到这个根目录。war和根文件夹存在。我用以下命令启动docker:
docker-compose up --build
当我访问localhost:8080Tomcat说Http状态404-未找到。
这里是执行docker compose up后的日志:
➜ PromogenServer git:(master) ✗ docker-compose up --build
Building backend
[+] Building 3.3s (16/16) FINISHED
=> [internal] load build definition from dockerfile 0.4s
=> => transferring dockerfile: 37B 0.0s
=> [internal] load .dockerignore 0.4s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/tomcat:jdk8-corretto 1.8s
=> [internal] load metadata for docker.io/library/maven:3.8.4-eclipse-temurin-17-alpine 1.7s
=> [stage-1 1/3] FROM docker.io/library/tomcat:jdk8-corretto@sha256:e78680bd172c7388fb9ed123423f671c2815560412ad2df8cc73f79b7922890e 0.0s
=> [internal] load build context 0.3s
=> => transferring context: 37.39kB 0.0s
=> [maven 1/7] FROM docker.io/library/maven:3.8.4-eclipse-temurin-17-alpine@sha256:d7d5ef47f898d0ef33fb472dc63fcc67face715e337efd1728107fc9e195388d 0.0s
=> CACHED [stage-1 2/3] RUN rm -rf /usr/local/tomcat/webapps/ROOT 0.0s
=> CACHED [maven 2/7] RUN mkdir -p /build 0.0s
=> CACHED [maven 3/7] COPY pom.xml /build 0.0s
=> CACHED [maven 4/7] COPY src /build/src 0.0s
=> CACHED [maven 5/7] WORKDIR /build 0.0s
=> CACHED [maven 6/7] RUN mvn -B dependency:resolve dependency:resolve-plugins 0.0s
=> CACHED [maven 7/7] RUN mvn -DskipTests clean package 0.0s
=> CACHED [stage-1 3/3] COPY --from=maven /build/target/promogen.war /usr/local/tomcat/webapps/ROOT.war 0.0s
=> exporting to image 0.3s
=> => exporting layers 0.0s
=> => writing image sha256:6a591e6448a22aefbd44a2c5b62940acdb46b581005de8e5fe940113c6de7acf 0.1s
=> => naming to docker.io/library/promogenserver_backend 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
Starting promogenserver_mysql_1 ... done
Starting promogenserver_backend_1 ... done
Attaching to promogenserver_mysql_1, promogenserver_backend_1
mysql_1 | 2021-12-20 15:19:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysql_1 | 2021-12-20 15:19:39+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_1 | 2021-12-20 15:19:39+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
mysql_1 | 2021-12-20T15:19:40.133565Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 1
mysql_1 | 2021-12-20T15:19:40.158480Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
mysql_1 | 2021-12-20T15:19:40.214360Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
backend_1 | 20-Dec-2021 15:19:42.185 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/10.0.14
backend_1 | 20-Dec-2021 15:19:42.192 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Dec 2 2021 22:01:36 UTC
backend_1 | 20-Dec-2021 15:19:42.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.0.14.0
backend_1 | 20-Dec-2021 15:19:42.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
backend_1 | 20-Dec-2021 15:19:42.193 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 5.10.47-linuxkit
backend_1 | 20-Dec-2021 15:19:42.194 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
backend_1 | 20-Dec-2021 15:19:42.194 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-1.8.0-amazon-corretto/jre
backend_1 | 20-Dec-2021 15:19:42.195 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_312-b07
backend_1 | 20-Dec-2021 15:19:42.195 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Amazon.com Inc.
backend_1 | 20-Dec-2021 15:19:42.196 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
backend_1 | 20-Dec-2021 15:19:42.196 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
backend_1 | 20-Dec-2021 15:19:42.209 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
backend_1 | 20-Dec-2021 15:19:42.210 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
backend_1 | 20-Dec-2021 15:19:42.211 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
backend_1 | 20-Dec-2021 15:19:42.211 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
backend_1 | 20-Dec-2021 15:19:42.212 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
backend_1 | 20-Dec-2021 15:19:42.212 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
backend_1 | 20-Dec-2021 15:19:42.213 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
backend_1 | 20-Dec-2021 15:19:42.213 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
backend_1 | 20-Dec-2021 15:19:42.213 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
backend_1 | 20-Dec-2021 15:19:42.234 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
backend_1 | 20-Dec-2021 15:19:42.234 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true], UDS [true].
backend_1 | 20-Dec-2021 15:19:42.248 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1g FIPS 21 Apr 2020]
backend_1 | 20-Dec-2021 15:19:43.623 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
backend_1 | 20-Dec-2021 15:19:43.690 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [2225] milliseconds
backend_1 | 20-Dec-2021 15:19:43.791 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
backend_1 | 20-Dec-2021 15:19:43.791 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.0.14]
backend_1 | 20-Dec-2021 15:19:43.873 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
mysql_1 | 2021-12-20T15:19:45.785479Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql_1 | 2021-12-20T15:19:47.572660Z 0 [System] [MY-010229] [Server] Starting XA crash recovery...
mysql_1 | 2021-12-20T15:19:47.610076Z 0 [System] [MY-010232] [Server] XA crash recovery finished.
mysql_1 | 2021-12-20T15:19:48.760762Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
mysql_1 | 2021-12-20T15:19:48.760872Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
mysql_1 | 2021-12-20T15:19:48.778784Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql_1 | 2021-12-20T15:19:48.779013Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql_1 | 2021-12-20T15:19:48.843650Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql_1 | 2021-12-20T15:19:49.192746Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql_1 | 2021-12-20T15:19:49.193439Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.27' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
backend_1 | 20-Dec-2021 15:19:51.902 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
backend_1 | 20-Dec-2021 15:19:52.042 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [8,166] ms
backend_1 | 20-Dec-2021 15:19:52.054 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
backend_1 | 20-Dec-2021 15:19:52.081 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [8390] milliseconds
编辑1:
我把tomcat的图片改成了
tomcat:8.5-jdk17-corretto
现在Spring应用程序启动了,但抱怨mysql连接:
Caused by: java.net.ConnectException: Connection refused
编辑2:
我解决了。我改变了我的application.properties
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/promogen
到
spring.datasource.url=jdbc:mysql://mysql:3306/promogen
其中mysql是我在docker compose的服务中使用的字符串。yml文件
我终于解决了。
看。
问题内容: 计划 我希望我的tomcat服务器能够在单独的容器中连接到我的MySQL服务器。 问题 Tomcat无法连接到MySQL 我使用了wordpress教程中的一些详细信息,这些信息涉及与mysql容器建立链接并创建指向MySQL的链接。 尽管tomcat和mysql旋转得很好,但我似乎无法使tomcat能够连接到MySQL,但是这些设置在我的本地计算机上也可以正常运行。 我也尝试使用它,
我的目标:我需要收集从运行的tomcat容器到Filebeat容器的tomcat日志。 问题:我不知道如何从Tomcat容器中获取收集的日志文件。 到目前为止我尝试过的内容:我尝试创建一个docker卷并将tomcat日志添加到该卷中,并从filebeat容器访问该卷,但没有成功。 docker-containers:包含3个主子目录(Tomcat、Nginx和Postgres)。ENV文件和do
本文向大家介绍Docker下Tomcat容器中使用Mysql的方法,包括了Docker下Tomcat容器中使用Mysql的方法的使用技巧和注意事项,需要的朋友参考一下 在这里我们使用Tomcat容器来运行war包,不过作为一个网站一个程序,如果需要用到数据库的,那么Tomcat容器中如何连接Mysql呢? 已经pull了tomcat和mysql镜像,可以使用docker的连接系统(–link)连接
> 我正试图弄清楚Kubernetes中的网络,尤其是多集装箱吊舱的处理。在我的简单场景中,我总共有3个豆荚。其中一个有两个容器,另一个只有一个容器,它希望与多容器吊舱中的特定容器通信。我想弄清楚kubernetes如何处理此类容器之间的通信。 为此,我在一个“sidecar体系结构”中有一个简单的多容器吊舱,YAML文件如下所示: > 我想用这个YAML文件实现的是,在pod“nginx”中,有
我想将Spring Boot应用程序作为WAR部署到Tomcat容器,但Tomcat无法启动该容器。我遵循了Spring Boot Reference中的“传统部署”一节。容器的线程大小设置为-xss4068,但我仍然收到堆栈溢出错误。 下面是堆栈跟踪: 我的pom.xml具有以下Spring Boot依赖项,其中spring-boot-starter-tomcat作用域设置为提供,如文档中所述。
在WildFly上部署我的应用程序后,我看到以下消息: