无法访问 tomcat,war 文件在与 docker 集成时未部署
Unable to reach tomcat, war file not deployed while integrating with docker
War 文件使用 mvn clean install
成功生成,然后在 terminal.The 中尝试使用 docker compose up --build
登录终端显示有没有创建表并且无法使用邮递员正确到达端点,tomcat 处于无法访问状态,因为 war 文件部署不当。我需要一个解决方案来将数据库与服务器连接起来并到达端点。我没有找到任何有用的信息来解决这个问题 issue.Help 我要获得正确的部署。
File structure
pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo</groupId>
<artifactId>EcomApplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>EcomApplication</name>
<packaging>war</packaging>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ecom</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
终端日志:
sowbharnika@SowbharnikasMBP EcomApplication % docker compose up --build
[+] Building 4.7s (11/11) FINISHED
=> [itomcat-ecom internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 217B 0.0s
=> [ipostgres-ecom internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 137B 0.0s
=> [itomcat-ecom internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [ipostgres-ecom internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [itomcat-ecom internal] load metadata for docker.io/library/tomcat:8.0-jre8 3.1s
=> [ipostgres-ecom internal] load metadata for docker.io/library/postgres:10.2 3.1s
=> CACHED [ipostgres-ecom 1/1] FROM docker.io/library/postgres:10.2@sha256:7361bae1fbf5642099663d1f02dc949cabde1f86727bf8ff00d0a8806640a617 0.0s
=> [itomcat-ecom] exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:388cf029752f4cac431dfb8eb41170dbd547bdb25e2542222d85355af59d96ed 0.0s
=> => naming to docker.io/library/ipostgres-ecom 0.0s
=> => writing image sha256:619f0674184633b5b1c4c81d08fc714b42625b547bd341486f321e706c75f744 0.0s
=> => naming to docker.io/library/itomcat-ecom 0.0s
=> [itomcat-ecom internal] load build context 1.0s
=> => transferring context: 37.56MB 1.0s
=> CACHED [itomcat-ecom 1/2] FROM docker.io/library/tomcat:8.0-jre8@sha256:268403c3fa09afd9310ced7e83ac021927dca0f04a394a80a0b0220f62e056ed 0.0s
=> [itomcat-ecom 2/2] ADD target/ecom.war /usr/local/tomcat/webapps 0.1s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 3/2
⠿ Network ecomapplication_default Created 3.9s
⠿ Container ecomapplication_cpostgres_1 Created 0.0s
⠿ Container ecomapplication_ctomcat_1 Created 0.0s
Attaching to cpostgres_1, ctomcat_1
cpostgres_1 | The files belonging to this database system will be owned by user "postgres".
cpostgres_1 | This user must also own the server process.
cpostgres_1 |
cpostgres_1 | The database cluster will be initialized with locale "en_US.utf8".
cpostgres_1 | The default database encoding has accordingly been set to "UTF8".
cpostgres_1 | The default text search configuration will be set to "english".
cpostgres_1 |
cpostgres_1 | Data page checksums are disabled.
cpostgres_1 |
cpostgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
cpostgres_1 | creating subdirectories ... ok
cpostgres_1 | selecting default max_connections ... 100
cpostgres_1 | selecting default shared_buffers ... 128MB
cpostgres_1 | selecting dynamic shared memory implementation ... posix
cpostgres_1 | creating configuration files ... ok
cpostgres_1 | running bootstrap script ... ok
cpostgres_1 | performing post-bootstrap initialization ... ok
cpostgres_1 | syncing data to disk ... ok
cpostgres_1 |
cpostgres_1 | Success. You can now start the database server using:
cpostgres_1 |
cpostgres_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
cpostgres_1 |
cpostgres_1 |
cpostgres_1 | WARNING: enabling "trust" authentication for local connections
cpostgres_1 | You can change this by editing pg_hba.conf or using the option -A, or
cpostgres_1 | --auth-local and --auth-host, the next time you run initdb.
cpostgres_1 | waiting for server to start....2021-06-17 05:54:27.217 UTC [40] LOG: listening on IPv4 address "127.0.0.1", port 5432
cpostgres_1 | 2021-06-17 05:54:27.217 UTC [40] LOG: could not bind IPv6 address "::1": Cannot assign requested address
cpostgres_1 | 2021-06-17 05:54:27.217 UTC [40] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
cpostgres_1 | 2021-06-17 05:54:27.221 UTC [40] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
cpostgres_1 | 2021-06-17 05:54:27.235 UTC [41] LOG: database system was shut down at 2021-06-17 05:54:26 UTC
cpostgres_1 | 2021-06-17 05:54:27.242 UTC [40] LOG: database system is ready to accept connections
cpostgres_1 | done
cpostgres_1 | server started
cpostgres_1 | CREATE DATABASE
cpostgres_1 |
cpostgres_1 | ALTER ROLE
cpostgres_1 |
cpostgres_1 |
cpostgres_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
cpostgres_1 |
cpostgres_1 | waiting for server to shut down....2021-06-17 05:54:27.715 UTC [40] LOG: received fast shutdown request
cpostgres_1 | 2021-06-17 05:54:27.718 UTC [40] LOG: aborting any active transactions
cpostgres_1 | 2021-06-17 05:54:27.719 UTC [40] LOG: worker process: logical replication launcher (PID 47) exited with exit code 1
cpostgres_1 | 2021-06-17 05:54:27.723 UTC [42] LOG: shutting down
cpostgres_1 | 2021-06-17 05:54:27.744 UTC [40] LOG: database system is shut down
cpostgres_1 | done
cpostgres_1 | server stopped
cpostgres_1 |
cpostgres_1 | PostgreSQL init process complete; ready for start up.
cpostgres_1 |
cpostgres_1 | 2021-06-17 05:54:27.828 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
cpostgres_1 | 2021-06-17 05:54:27.828 UTC [1] LOG: listening on IPv6 address "::", port 5432
cpostgres_1 | 2021-06-17 05:54:27.832 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
cpostgres_1 | 2021-06-17 05:54:27.845 UTC [67] LOG: database system was shut down at 2021-06-17 05:54:27 UTC
cpostgres_1 | 2021-06-17 05:54:27.852 UTC [1] LOG: database system is ready to accept connections
ctomcat_1 | Listening for transport dt_socket at address: 18000
ctomcat_1 | 17-Jun-2021 05:54:32.012 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.53
ctomcat_1 | 17-Jun-2021 05:54:32.017 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 29 2018 14:42:45 UTC
ctomcat_1 | 17-Jun-2021 05:54:32.017 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.53.0
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 5.10.25-linuxkit
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_181-8u181-b13-1~deb9u1-b13
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=18000,server=y,suspend=n
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.17 using APR version 1.5.2.
ctomcat_1 | 17-Jun-2021 05:54:32.021 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
ctomcat_1 | 17-Jun-2021 05:54:32.026 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0f 25 May 2017)
ctomcat_1 | 17-Jun-2021 05:54:32.198 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
ctomcat_1 | 17-Jun-2021 05:54:32.212 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
ctomcat_1 | 17-Jun-2021 05:54:32.214 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 863 ms
ctomcat_1 | 17-Jun-2021 05:54:32.270 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
ctomcat_1 | 17-Jun-2021 05:54:32.270 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
ctomcat_1 | 17-Jun-2021 05:54:32.320 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/ecom.war
ctomcat_1 | 17-Jun-2021 05:54:33.034 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
ctomcat_1 | 17-Jun-2021 05:54:33.037 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
ctomcat_1 | 17-Jun-2021 05:54:35.180 INFO [localhost-startStop-1] 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.
ctomcat_1 | 17-Jun-2021 05:54:35.450 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/ecom.war has finished in 3,130 ms
ctomcat_1 | 17-Jun-2021 05:54:35.452 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
ctomcat_1 | 17-Jun-2021 05:54:35.651 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 198 ms
ctomcat_1 | 17-Jun-2021 05:54:35.651 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
ctomcat_1 | 17-Jun-2021 05:54:35.682 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 31 ms
ctomcat_1 | 17-Jun-2021 05:54:35.683 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
ctomcat_1 | 17-Jun-2021 05:54:35.701 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 18 ms
ctomcat_1 | 17-Jun-2021 05:54:35.701 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
ctomcat_1 | 17-Jun-2021 05:54:35.727 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 25 ms
ctomcat_1 | 17-Jun-2021 05:54:35.727 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
ctomcat_1 | 17-Jun-2021 05:54:35.744 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 17 ms
ctomcat_1 | 17-Jun-2021 05:54:35.763 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
ctomcat_1 | 17-Jun-2021 05:54:35.788 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
ctomcat_1 | 17-Jun-2021 05:54:35.799 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3584 ms
虽然调试 tomcat 容器日志没有显示任何错误,说明到达 tomcat server.So 的问题,但很难调试。
邮递员
Endpoint status
Docker 撰写文件
version: '2'
services:
ctomcat:
build:
context: .
dockerfile: ./docker/tomcat/Dockerfile
ports:
- "8080:8080"
- "18000:18000"
image: itomcat-ecom
depends_on:
- cpostgres
cpostgres:
build:
context: "./docker/postgres"
restart: always
image: ipostgres-ecom
ports:
- 15432:5432
Docker postgres 文件
FROM postgres:10.2
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD password
ENV POSTGRES_DB ecomdb
Docker tomcat
的文件
FROM tomcat:8.0-jre8
ADD target/ecom.war /usr/local/tomcat/webapps
ENV JPDA_ADDRESS 18000
ENV JPDA_TRANSPORT=dt_socket
EXPOSE 8080
EXPOSE 18000
CMD ["catalina.sh", "jpda", "run"]
application.properties
spring.datasource.url=jdbc:postgresql://cpostgres:5432/ecomdb
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.initialization-mode=always
spring.datasource.initialize=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.show_sql=true
在 Docker 合成文件中,为 tomcat 拉取的图像有不同的版本,仅支持特定的 java 版本。因此,要么更改支持 Java 版本 11(在 pom 文件中)的 tomcat 图像版本文件,要么更改 Java 版本,如下所述:
在属性下的 POM 文件中做这样的更改 -
<properties>
<java.version>1.8</java.version>
</properties>
Error shown in terminal logs is tough to debug as it does not show any error at all instead of it, it completely ignores the artifactId
if it can't be deployed.
备注
我们需要确保三件事...
War 应复制到 tomcat 内的正确目录,如 -
(/usr/local/tomcat/webapps).
确保您的 java 版本与您的 tomcat 图像匹配
使用.
确保您的 sprint 启动应用程序 class 是正确的并且有
实施 SpringBootServletInitializer
After doing above mentioned changes, project will get deployed
successfully, will get connected to database & will access endpoints
as well.
War 文件使用 mvn clean install
成功生成,然后在 terminal.The 中尝试使用 docker compose up --build
登录终端显示有没有创建表并且无法使用邮递员正确到达端点,tomcat 处于无法访问状态,因为 war 文件部署不当。我需要一个解决方案来将数据库与服务器连接起来并到达端点。我没有找到任何有用的信息来解决这个问题 issue.Help 我要获得正确的部署。
File structure
pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo</groupId>
<artifactId>EcomApplication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>EcomApplication</name>
<packaging>war</packaging>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>ecom</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
终端日志:
sowbharnika@SowbharnikasMBP EcomApplication % docker compose up --build
[+] Building 4.7s (11/11) FINISHED
=> [itomcat-ecom internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 217B 0.0s
=> [ipostgres-ecom internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 137B 0.0s
=> [itomcat-ecom internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [ipostgres-ecom internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [itomcat-ecom internal] load metadata for docker.io/library/tomcat:8.0-jre8 3.1s
=> [ipostgres-ecom internal] load metadata for docker.io/library/postgres:10.2 3.1s
=> CACHED [ipostgres-ecom 1/1] FROM docker.io/library/postgres:10.2@sha256:7361bae1fbf5642099663d1f02dc949cabde1f86727bf8ff00d0a8806640a617 0.0s
=> [itomcat-ecom] exporting to image 0.2s
=> => exporting layers 0.2s
=> => writing image sha256:388cf029752f4cac431dfb8eb41170dbd547bdb25e2542222d85355af59d96ed 0.0s
=> => naming to docker.io/library/ipostgres-ecom 0.0s
=> => writing image sha256:619f0674184633b5b1c4c81d08fc714b42625b547bd341486f321e706c75f744 0.0s
=> => naming to docker.io/library/itomcat-ecom 0.0s
=> [itomcat-ecom internal] load build context 1.0s
=> => transferring context: 37.56MB 1.0s
=> CACHED [itomcat-ecom 1/2] FROM docker.io/library/tomcat:8.0-jre8@sha256:268403c3fa09afd9310ced7e83ac021927dca0f04a394a80a0b0220f62e056ed 0.0s
=> [itomcat-ecom 2/2] ADD target/ecom.war /usr/local/tomcat/webapps 0.1s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 3/2
⠿ Network ecomapplication_default Created 3.9s
⠿ Container ecomapplication_cpostgres_1 Created 0.0s
⠿ Container ecomapplication_ctomcat_1 Created 0.0s
Attaching to cpostgres_1, ctomcat_1
cpostgres_1 | The files belonging to this database system will be owned by user "postgres".
cpostgres_1 | This user must also own the server process.
cpostgres_1 |
cpostgres_1 | The database cluster will be initialized with locale "en_US.utf8".
cpostgres_1 | The default database encoding has accordingly been set to "UTF8".
cpostgres_1 | The default text search configuration will be set to "english".
cpostgres_1 |
cpostgres_1 | Data page checksums are disabled.
cpostgres_1 |
cpostgres_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
cpostgres_1 | creating subdirectories ... ok
cpostgres_1 | selecting default max_connections ... 100
cpostgres_1 | selecting default shared_buffers ... 128MB
cpostgres_1 | selecting dynamic shared memory implementation ... posix
cpostgres_1 | creating configuration files ... ok
cpostgres_1 | running bootstrap script ... ok
cpostgres_1 | performing post-bootstrap initialization ... ok
cpostgres_1 | syncing data to disk ... ok
cpostgres_1 |
cpostgres_1 | Success. You can now start the database server using:
cpostgres_1 |
cpostgres_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
cpostgres_1 |
cpostgres_1 |
cpostgres_1 | WARNING: enabling "trust" authentication for local connections
cpostgres_1 | You can change this by editing pg_hba.conf or using the option -A, or
cpostgres_1 | --auth-local and --auth-host, the next time you run initdb.
cpostgres_1 | waiting for server to start....2021-06-17 05:54:27.217 UTC [40] LOG: listening on IPv4 address "127.0.0.1", port 5432
cpostgres_1 | 2021-06-17 05:54:27.217 UTC [40] LOG: could not bind IPv6 address "::1": Cannot assign requested address
cpostgres_1 | 2021-06-17 05:54:27.217 UTC [40] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
cpostgres_1 | 2021-06-17 05:54:27.221 UTC [40] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
cpostgres_1 | 2021-06-17 05:54:27.235 UTC [41] LOG: database system was shut down at 2021-06-17 05:54:26 UTC
cpostgres_1 | 2021-06-17 05:54:27.242 UTC [40] LOG: database system is ready to accept connections
cpostgres_1 | done
cpostgres_1 | server started
cpostgres_1 | CREATE DATABASE
cpostgres_1 |
cpostgres_1 | ALTER ROLE
cpostgres_1 |
cpostgres_1 |
cpostgres_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
cpostgres_1 |
cpostgres_1 | waiting for server to shut down....2021-06-17 05:54:27.715 UTC [40] LOG: received fast shutdown request
cpostgres_1 | 2021-06-17 05:54:27.718 UTC [40] LOG: aborting any active transactions
cpostgres_1 | 2021-06-17 05:54:27.719 UTC [40] LOG: worker process: logical replication launcher (PID 47) exited with exit code 1
cpostgres_1 | 2021-06-17 05:54:27.723 UTC [42] LOG: shutting down
cpostgres_1 | 2021-06-17 05:54:27.744 UTC [40] LOG: database system is shut down
cpostgres_1 | done
cpostgres_1 | server stopped
cpostgres_1 |
cpostgres_1 | PostgreSQL init process complete; ready for start up.
cpostgres_1 |
cpostgres_1 | 2021-06-17 05:54:27.828 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
cpostgres_1 | 2021-06-17 05:54:27.828 UTC [1] LOG: listening on IPv6 address "::", port 5432
cpostgres_1 | 2021-06-17 05:54:27.832 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
cpostgres_1 | 2021-06-17 05:54:27.845 UTC [67] LOG: database system was shut down at 2021-06-17 05:54:27 UTC
cpostgres_1 | 2021-06-17 05:54:27.852 UTC [1] LOG: database system is ready to accept connections
ctomcat_1 | Listening for transport dt_socket at address: 18000
ctomcat_1 | 17-Jun-2021 05:54:32.012 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.53
ctomcat_1 | 17-Jun-2021 05:54:32.017 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jun 29 2018 14:42:45 UTC
ctomcat_1 | 17-Jun-2021 05:54:32.017 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.53.0
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 5.10.25-linuxkit
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_181-8u181-b13-1~deb9u1-b13
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
ctomcat_1 | 17-Jun-2021 05:54:32.018 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
ctomcat_1 | 17-Jun-2021 05:54:32.019 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=18000,server=y,suspend=n
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
ctomcat_1 | 17-Jun-2021 05:54:32.020 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.17 using APR version 1.5.2.
ctomcat_1 | 17-Jun-2021 05:54:32.021 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
ctomcat_1 | 17-Jun-2021 05:54:32.026 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.1.0f 25 May 2017)
ctomcat_1 | 17-Jun-2021 05:54:32.198 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-apr-8080"]
ctomcat_1 | 17-Jun-2021 05:54:32.212 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-apr-8009"]
ctomcat_1 | 17-Jun-2021 05:54:32.214 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 863 ms
ctomcat_1 | 17-Jun-2021 05:54:32.270 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
ctomcat_1 | 17-Jun-2021 05:54:32.270 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.53
ctomcat_1 | 17-Jun-2021 05:54:32.320 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /usr/local/tomcat/webapps/ecom.war
ctomcat_1 | 17-Jun-2021 05:54:33.034 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
ctomcat_1 | 17-Jun-2021 05:54:33.037 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
ctomcat_1 | 17-Jun-2021 05:54:35.180 INFO [localhost-startStop-1] 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.
ctomcat_1 | 17-Jun-2021 05:54:35.450 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /usr/local/tomcat/webapps/ecom.war has finished in 3,130 ms
ctomcat_1 | 17-Jun-2021 05:54:35.452 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples
ctomcat_1 | 17-Jun-2021 05:54:35.651 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/examples has finished in 198 ms
ctomcat_1 | 17-Jun-2021 05:54:35.651 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/manager
ctomcat_1 | 17-Jun-2021 05:54:35.682 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/manager has finished in 31 ms
ctomcat_1 | 17-Jun-2021 05:54:35.683 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT
ctomcat_1 | 17-Jun-2021 05:54:35.701 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 18 ms
ctomcat_1 | 17-Jun-2021 05:54:35.701 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/host-manager
ctomcat_1 | 17-Jun-2021 05:54:35.727 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/host-manager has finished in 25 ms
ctomcat_1 | 17-Jun-2021 05:54:35.727 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs
ctomcat_1 | 17-Jun-2021 05:54:35.744 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 17 ms
ctomcat_1 | 17-Jun-2021 05:54:35.763 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-apr-8080"]
ctomcat_1 | 17-Jun-2021 05:54:35.788 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-apr-8009"]
ctomcat_1 | 17-Jun-2021 05:54:35.799 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3584 ms
虽然调试 tomcat 容器日志没有显示任何错误,说明到达 tomcat server.So 的问题,但很难调试。
邮递员
Endpoint status
Docker 撰写文件
version: '2'
services:
ctomcat:
build:
context: .
dockerfile: ./docker/tomcat/Dockerfile
ports:
- "8080:8080"
- "18000:18000"
image: itomcat-ecom
depends_on:
- cpostgres
cpostgres:
build:
context: "./docker/postgres"
restart: always
image: ipostgres-ecom
ports:
- 15432:5432
Docker postgres 文件
FROM postgres:10.2
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD password
ENV POSTGRES_DB ecomdb
Docker tomcat
的文件FROM tomcat:8.0-jre8
ADD target/ecom.war /usr/local/tomcat/webapps
ENV JPDA_ADDRESS 18000
ENV JPDA_TRANSPORT=dt_socket
EXPOSE 8080
EXPOSE 18000
CMD ["catalina.sh", "jpda", "run"]
application.properties
spring.datasource.url=jdbc:postgresql://cpostgres:5432/ecomdb
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.initialization-mode=always
spring.datasource.initialize=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.properties.hibernate.show_sql=true
在 Docker 合成文件中,为 tomcat 拉取的图像有不同的版本,仅支持特定的 java 版本。因此,要么更改支持 Java 版本 11(在 pom 文件中)的 tomcat 图像版本文件,要么更改 Java 版本,如下所述:
在属性下的 POM 文件中做这样的更改 -
<properties>
<java.version>1.8</java.version>
</properties>
Error shown in terminal logs is tough to debug as it does not show any error at all instead of it, it completely ignores the artifactId if it can't be deployed.
备注
我们需要确保三件事...
War 应复制到 tomcat 内的正确目录,如 - (/usr/local/tomcat/webapps).
确保您的 java 版本与您的 tomcat 图像匹配 使用.
确保您的 sprint 启动应用程序 class 是正确的并且有 实施 SpringBootServletInitializer
After doing above mentioned changes, project will get deployed successfully, will get connected to database & will access endpoints as well.