【问题标题】:Docker in Windows: Failed to load native library 'libnative-platform.so' for Linux amd64 [duplicate]Windows 中的 Docker:无法为 Linux amd64 加载本机库“libnative-platform.so”[重复]
【发布时间】:2018-05-10 11:32:01
【问题描述】:

我正在尝试在(通过)docker 中运行项目。它在 unix 服务器上正常工作。我在本地机器上使用 Windows。

项目结构如下:

docker-compose.yml内容:

version: '3'
services:
  sftp:
    image: atmoz/sftp
    restart: on-failure
    command: missftp:missftp:::destWorking,destRejected,destSuccess,attachments
  mailer:
    image: mailhog/mailhog
    ports:
      - 8025:8025
      - 1025:1025
    restart: on-failure
  mongo:
    image: mongo
    restart: on-failure
  mongo-express:
    image: mongo-express
    restart: on-failure
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_SERVER=mongo
      - ME_CONFIG_BASICAUTH_USERNAME=admin
      - ME_CONFIG_BASICAUTH_PASSWORD=1234
  data-service:
    build:
      context: .
      dockerfile: Dockerfile.data-service
    ports:
      - 8801:8801
      - 8802:8802
    restart: on-failure
    volumes:
         - /opt/app/mis/attachments:/attachments
    environment:
      - SPRING_DATA_MONGODB_HOST=mongo
      - SPRING_MAIL_HOST=mailer
      - SPRING_MAIL_USERNAME=apikey
      - SPRING_MAIL_PASSWORD=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
      - SPRING_MAIL_PORT=465
      ...
  upload-service:
    build:
      context: .
      dockerfile: Dockerfile.upload-service
    ports:
      - 8082:8082
      - 8083:8083
    restart: on-failure
    environment:
      - SPRING_DATA_MONGODB_HOST=mongo
      ...

Dockerfile.data-service文件内容:

FROM gradle:alpine
COPY / ./
RUN gradle build
ENTRYPOINT java -jar ./mis-data-service/build/libs/mis-data-service-0.1.jar

然后我执行以下命令:

docker-compose -f docker-compose.yml up

结果:

Building data-service
Step 1/4 : FROM gradle:alpine
 ---> f438b7d58d0a
Step 2/4 : COPY / ./
 ---> Using cache
 ---> b72d0e76b86c
Step 3/4 : RUN gradle build
 ---> Running in 7ba780a524e5

FAILURE: Build failed with an exception.

* What went wrong:
Failed to load native library 'libnative-platform.so' for Linux amd64.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org
ERROR: Service 'data-service' failed to build: The command '/bin/sh -c gradle build' returned a non-zero code: 1

我做错了什么?如何解决此错误?

附言

我使用 Gradle 4.6

【问题讨论】:

    标签: java windows docker gradle docker-compose


    【解决方案1】:

    https://stackoverflow.com/a/39345276/372019:

    请在 Dockerfile 中 RUN gradle build 命令之前添加以下命令:

    RUN apk add --no-cache libstdc++
    

    【讨论】:

      【解决方案2】:

      github 中似乎有几个与此相关的问题,尽管没有明确提及 Windows 主机

      人们提到的一些正在为他们解决问题的事情:

      • 使用较新的 cradle,据报道 gradle 3.5 可以工作,而以前的版本则不能。至少确认您运行的不是旧版本。
      • GRADLE_USER_HOME 环境变量未设置或可供运行的用户访问,您还应确认:chmod 000 $GRADLE_USER_HOME
      • 使用--privileged 标志运行容器
      • 以 root 身份运行(如果您能以其他方式运行,则不推荐):

      以root身份运行的Dockerfile:

      FROM gradle:alpine
      USER root
      

      【讨论】:

      • 我使用 Gradle 46
      • 环境变量 GRADLE_USER_HOME 未定义
      • D:\work\mis\mis_official\midnight-integration-service>设置 GRADLE_HOME GRADLE_HOME=C:\Program Files (x86)\gradle-4.6-bin\gradle-4.6
      • 你能用 --privileged 标志显示完整的命令文本吗?
      • 以 root 身份运行我使用的是 Windows,所以我不知道你在说什么
      【解决方案3】:

      由于 gradle 机器没有执行 gradle 命令的完整权限, 您可以尝试以“root用户”身份运行具有用户权限的docker机器吗

      FROM gradle:alpine
      USER root
      

      或者您使用“-u root”参数执行 docker run 命令,

      更多详情请参考:https://github.com/keeganwitt/docker-gradle/issues/29

      【讨论】:

        猜你喜欢
        • 2018-07-17
        • 2016-10-14
        • 2016-02-28
        • 1970-01-01
        • 1970-01-01
        • 2018-06-24
        • 2013-06-09
        • 2021-08-22
        • 2014-05-06
        相关资源
        最近更新 更多