Docker image build error: shell script file is copied in the workdir but it says the file is not found

问题描述 投票:0回答:0

我正在尝试使用 alpine 对遗留 java 项目进行 dockerize。 我的机器在 Windows 10 上运行,我正在使用适用于 Windows 的 Docker Desktop。

这是我的

Dockerfile

FROM openjdk:8u171-jdk-alpine
RUN apk -U add tini
WORKDIR /mnt
COPY ./ ./
RUN chmod +x ./posix-compile.sh && ls && sh ./posix-compile.sh
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait /wait
RUN chmod +x /wait

EXPOSE 8484
ENTRYPOINT ["tini", "--"]
CMD /wait && sh ./posix-launch.sh

这是

docker-compose.yml

version: '3'
services:
  test_server:
    network_mode: "host"
    build: .
    depends_on:
      - db
    environment:
      WAIT_HOSTS: localhost:3306
    
  db:
    network_mode: "host"
    image: mysql:5.6
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      MYSQL_DATABASE: "test"
      MYSQL_USER: "root"
      MYSQL_PASSWORD: ""
    volumes:
      - ./sql:/docker-entrypoint-initdb.d

还有臭名昭著的

posix-compile.sh

#!/bin/bash

src=src
dist=dist

cores=$(echo cores/*)
cores=${cores// /:}

mkdir -p $dist
javac -d $dist -cp $cores $(find $src -name "*.java")

我尝试通过运行此命令来构建图像:

docker build --progress=plain --no-cache -t image_name:test_server .

这里是错误日志:

#1 [internal] load build definition from Dockerfile
#1 sha256:734b5acd3990699a89640afb38e612dcd101941fa334de84db76e0ef22a09a5c
#1 transferring dockerfile: 32B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:0798a5154adb31bf1ecaeae8a0e68f072b7918021ba50681ef94b7c7fc95c9d2
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/openjdk:8u171-jdk-alpine
#3 sha256:082938b39d87076fb3dd83e3b06c987c66345165a901b4b2a8daff42aa3e073e
#3 ...

#4 [auth] library/openjdk:pull token for registry-1.docker.io
#4 sha256:d7d7bd54dd220e3a332acfbd133903ef12601aeac31ac9eca3e7d27be90a00f4
#4 DONE 0.0s

#3 [internal] load metadata for docker.io/library/openjdk:8u171-jdk-alpine
#3 sha256:082938b39d87076fb3dd83e3b06c987c66345165a901b4b2a8daff42aa3e073e
#3 DONE 1.0s

#5 [1/7] FROM docker.io/library/openjdk:8u171-jdk-alpine@sha256:a2d7b02891b158d01523e26ad069d40d5eb2c14d6943cf4df969b097acaa77d3
#5 sha256:c5bf96b6cf0bb3e3a19eb27818366c65d6f0a496829955612c998c4a5020f471
#5 CACHED

#8 [internal] load build context
#8 sha256:b6ac95785d97e335c0770a7341974fecce99dea7a6ee67dabf0c292ee17c876a
#8 transferring context: 257.03kB 0.4s done
#8 DONE 0.4s

#11 https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait
#11 sha256:772645aa2e9596a9e400a39317096d2758fef9afc8f072168bdd012fbf19df9d
#11 CACHED

#6 [2/7] RUN apk -U add tini
#6 sha256:07339a1c0a2f75fcc8bbf72f912365594e3fee755a0d89a61a140b919773cec0
#6 0.432 fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
#6 0.645 fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
#6 0.796 (1/1) Installing tini (0.18.0-r0)
#6 0.837 Executing busybox-1.28.4-r1.trigger
#6 0.841 OK: 101 MiB in 54 packages
#6 DONE 0.9s

#7 [3/7] WORKDIR /mnt
#7 sha256:f3e442bf975f4c835b95cc860e90d21cc7d4355767d706b9875f300eb48b9d8b
#7 DONE 0.1s

#9 [4/7] COPY ./ ./
#9 sha256:e792397fe61887dc71f5994ad4ae2cb2a221433ec61a167e127fc1201fba66d0
#9 DONE 0.3s

#10 [5/7] RUN chmod +x ./posix-compile.sh && ls && sh ./posix-compile.sh
#10 sha256:25c8585839839af83a646d324377d4be64ee481e18347151ce18c6852d916443
#10 0.418 Dockerfile
#10 0.418 LICENSE
#10 0.418 README.md
#10 0.418 config.yaml
#10 0.418 cores
#10 0.418 dist_test
#10 0.418 docker-compose.yml
#10 0.418 linux-compile.sh
#10 0.418 linux-launch.sh
#10 0.418 logs
#10 0.418 manifest.mf
#10 0.418 posix-compile.sh
#10 0.418 posix-launch.sh
#10 0.418 scripts
#10 0.418 sql
#10 0.418 src
#10 0.418 tools
: not found/posix-compile.sh: line 2:
: not found/posix-compile.sh: line 5:
: not found/posix-compile.sh: line 8:
: No such file or directory
#10 0.545 javac: invalid flag:
#10 0.545 Usage: javac <options> <source files>
#10 0.545 use -help for a list of possible options
#10 ERROR: executor failed running [/bin/sh -c chmod +x ./posix-compile.sh && ls && sh ./posix-compile.sh]: exit code: 2
------
 > [5/7] RUN chmod +x ./posix-compile.sh && ls && sh ./posix-compile.sh:
------
executor failed running [/bin/sh -c chmod +x ./posix-compile.sh && ls && sh ./posix-compile.sh]: exit code: 2

这是我项目根目录的快照,以帮助理解项目结构。

ls
的结果显示,
posic-compile.sh
在那里,我不明白为什么或怎么说找不到这个文件。

我以为可能是权限问题,这就是为什么我在

Dockerfile
的第5行的开头添加,
chmod +x ./posix-compile.sh
,但是它没有改变任何东西。

我尝试通过指定

/mnt/posix-compile.sh
使用绝对路径,它也没有用。

java docker shell posix alpine-linux
© www.soinside.com 2019 - 2024. All rights reserved.