gpt4 book ai didi

java - Docker:OCI 运行时创建失败:container_linux.go:349:启动容器进程导致 "exec:\"java\": executable file not found in $PATH"

转载 作者:行者123 更新时间:2023-12-01 16:52:50 27 4
gpt4 key购买 nike

我有一个可与 Postgres 数据库配合使用的 Java Spring Boot 应用程序。我想对它们都使用 Docker。最初,我创建了一个 docker-compose.yml 文件,如下所示:

version: '3.2'
services:
postgres:
restart: always
container_name: sample_db
image: postgres:10.4
ports:
- '5432:5432'
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_DB=${POSTGRES_DB}
# APP**
web:
build: .
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/test
expose:
- '8080'
ports:
- '8080:8080'

然后,在 application.properties 文件中我定义了以下属性。

server.port=8080
spring.jpa.generate-ddl=true


spring.datasource.url=jdbc:postgresql://postgres:5432/test
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.flyway.baseline-on-migrate=true
spring.flyway.enabled=true

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = validate
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: true

此外,我在项目目录中创建了一个 Dockerfile,如下所示:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
EXPOSE 8080
RUN mkdir -p /app/
RUN mkdir -p /app/logs/
COPY target/household-0.0.1-SNAPSHOT.jar /app/app.jar
FROM postgres
ENV POSTGRES_PASSWORD postgres
ENV POSTGRES_DB testdb
COPY schema.sql /docker-entrypoint-initdb.d/
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]

我发出了这些命令,最终出现了如下错误。

mvn 清理包docker build ./-t springbootapp
docker-compose up

ERROR: for household-appliances_web_1  Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"java\": executable file not found in $PATH": unknown

ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"java\": executable file not found in $PATH": unknown
ERROR: Encountered errors while bringing up the project.

请大家帮忙!

最佳答案

我在为 Docker 设置 Rails 应用程序时遇到此错误:

我的docker-entrypoint.sh文件被放置在我的应用程序的文件夹中,内容如下:

#!/bin/sh

set -e

bundle exec rails server -b 0.0.0.0 -e production

在我的 Dockerfile 中,我这样定义了入口点命令:

RUN ["chmod", "+x", "docker-entrypoint.sh"]
ENTRYPOINT ["docker-entrypoint.sh"]

但是当我运行 docker-compose up command 时,出现以下错误:

ERROR: for app Cannot start service app: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "docker-entrypoint.sh": executable file not found in $PATH": unknown

这是我修复它的方法:

指定 docker-entrypoint.sh 的实际路径文件,即代替:

ENTRYPOINT ["docker-entrypoint.sh"]

使用

ENTRYPOINT ["./docker-entrypoint.sh"]

这告诉 docker docker-entrypoint.sh文件位于应用程序的 root 文件夹中,您还可以指定不同的路径,如果 docker-entrypoint.sh 的路径有所不同,但请确保您不会错过 ./前缀为 docker-entrypoint.sh文件路径定义。

所以我的后来看起来像这样:

RUN ["chmod", "+x", "docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]

仅此而已。

我希望这有帮助

关于java - Docker:OCI 运行时创建失败:container_linux.go:349:启动容器进程导致 "exec:\"java\": executable file not found in $PATH",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61656204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com