简体   繁体   English

Docker:OCI 运行时创建失败:container_linux.go:349:启动容器进程导致“exec:\”java\“:$PATH 中找不到可执行文件”

[英]Docker: OCI runtime create failed: container_linux.go:349: starting container process caused “exec: \”java\“: executable file not found in $PATH”

I have a Java Spring Boot app which works with a Postgres database.我有一个与 Postgres 数据库一起使用的 Java Spring 引导应用程序。 I want to use Docker for both of them.我想对他们两个都使用 Docker 。 Initially, I created a docker-compose.yml file as given below:最初,我创建了一个 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'

Then,inside the application.properties file I defined the following properties.然后,在 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

Also,I created a Dockerfile in my project directory, which looks like this:另外,我在我的项目目录中创建了一个 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"]

I issued these commands and ended up in the error as given below.我发出了这些命令并最终出现如下错误。

mvn clean package docker build./ -t springbootapp mvn clean package docker build./ -t springbootapp
docker-compose up docker-compose向上

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.

Kindly anyone help on this!请任何人帮助解决这个问题!

application.properties file content is irrelevant to question, so you can remove it. application.properties文件内容与问题无关,因此您可以将其删除。 Lets look to your Dockerfile, I will remove irrelevant code让我们看看你的 Dockerfile,我会删除不相关的代码

FROM openjdk:8-jdk-alpine
COPY target/household-0.0.1-SNAPSHOT.jar /app/app.jar

FROM postgres
COPY schema.sql /docker-entrypoint-initdb.d/
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]

So you are using multistage building, you just copying file from host to first stage.因此,您正在使用多阶段构建,您只需将文件从主机复制到第一阶段。 As final stage you are using postgres image and telling to set ENTRYPOINT to java , but java does not exists in the postgres image.作为最后阶段,您正在使用postgres图像并告诉将ENTRYPOINT设置为java ,但 java 在 postgres 图像中不存在。

What you should change:你应该改变什么:

You should have postgres containe separated from java container like you have it in docker-compose.yml file and second suggestion use CMD instead of ENTRYPOINT .您应该将 postgres 包含与 java 容器分开,就像您在docker-compose.yml文件中一样,第二个建议使用CMD而不是ENTRYPOINT Your final Dockerfile should be你最终的 Dockerfile 应该是

FROM openjdk:8-jdk-alpine
COPY target/household-0.0.1-SNAPSHOT.jar /app/app.jar
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app/app.jar"]

I had this error when setting up a Rails appliation for Docker:为 Docker 设置 Rails 应用程序时出现此错误:

My docker-entrypoint.sh file was placed in the root folder of my application with this content:我的docker-entrypoint.sh文件被放置在我的应用程序的文件夹中,其中包含以下内容:

#!/bin/sh

set -e

bundle exec rails server -b 0.0.0.0 -e production

And in my Dockerfile, I defined my entrypoint command this way:在我的 Dockerfile 中,我这样定义了我的入口点命令:

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

But I was getting the error below when I ran the docker-compose up command :但是当我运行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错误:对于应用程序无法启动服务应用程序:OCI 运行时创建失败:container_linux.go:349:启动容器进程导致“exec:”docker-entrypoint.sh“:$ PATH 中找不到可执行文件”:未知

Here's how I fixed it :这是我修复它的方法

Specify an actual path for the docker-entrypoint.sh file, that is instead of:指定docker-entrypoint.sh文件的实际路径,而不是:

ENTRYPOINT ["docker-entrypoint.sh"]

use利用

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

This tells docker that the docker-entrypoint.sh file is located in the root folder of your application, you could also specify a different path if the path to your docker-entrypoint.sh is different, but ensure you do not miss out on the ./ prefix to your docker-entrypoint.sh file path definition.这告诉 docker docker-entrypoint.sh文件位于应用程序的文件夹中,如果docker-entrypoint.sh的路径不同,您也可以指定不同的路径,但请确保不要错过./作为docker-entrypoint.sh文件路径定义的前缀。

So mine looked like this afterwards:所以我的后来看起来像这样:

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

That's all.就这样。

I hope this helps我希望这有帮助

The FROM postgres line creates a second image (it is a multi-stage build ) that is based on the PostgreSQL database server. FROM postgres行创建基于 PostgreSQL 数据库服务器的第二个映像(它是一个多阶段构建)。 Everything above that line is effectively ignored.该行之上的所有内容都被有效地忽略了。 So your final image is running a second database, and not a JVM.因此,您的最终映像正在运行第二个数据库,而不是 JVM。

You don't need this line, and you don't need to extend the database server to run a client.您不需要这一行,也不需要扩展数据库服务器来运行客户端。 You can delete this line, and the application will start up.您可以删除此行,应用程序将启动。

You'll also have to separately get that schema file into the database container.您还必须单独将该模式文件放入数据库容器中。 Just bind-mounting the file in volumes: in the docker-compose.yml file is an easy path.只需在volumes:docker-compose.yml文件中是一条简单的路径。 If you have a database migration system in your application, running migrations on startup will be a more robust approach.如果您的应用程序中有数据库迁移系统,则在启动时运行迁移将是一种更强大的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM