gpt4 book ai didi

docker - 无法使用ENTRYPOINT Docker运行script.sh

转载 作者:行者123 更新时间:2023-12-02 19:34:24 25 4
gpt4 key购买 nike

我有以下脚本:

echo "** Creating data volume."
docker volume create --name sData

echo "** Build the java image that will be used to compile a Java class."
docker build -t bh/java:1.0 ./Java

echo "** Run the Java container to compile a Java class."
docker run --name "java-compile" -v sData:/usr/src/data bh/java:1.0

在Java文件夹中,我具有以下Dockerfile:
FROM openjdk:7 AS build-env

# Copy java file to compile and run
COPY ./Main.java /usr/src/myapp/Main.java

WORKDIR /usr/src/myapp

RUN ls -al

# Copy script.sh to root folder
COPY ./script.sh /usr/src/data/script.sh

RUN chmod 777 /usr/src/data/script.sh

ENTRYPOINT ["sh", "/usr/src/data/script.sh"]

和script.sh文件:
#!bin/sh

# Go to myapp
cd /usr/src/myapp

#echo "Listing all files in directory - myapp"
ls -al

#echo "Compiling the java class"
javac Main.java

# Move the .class file
echo "Moving Main.class to /usr/data/Main.class"
mv /usr/src/myapp/Main.class /usr/src/data/Main.class

cd /usr/src/data

#echo "Listing all files in directory - data"
ls -al

当我如上所述运行容器时,出现以下错误:
: not foundta/script.sh: 2: /usr/src/data/script.sh:
's: invalid option -- '
Try 'ls --help' for more information.
: not foundta/script.sh: 4: /usr/src/data/script.sh:
: not foundta/script.sh: 5: /usr/src/data/script.sh:
: not foundta/script.sh: 8: /usr/src/data/script.sh:
: not foundta/script.sh: 11: /usr/src/data/script.sh:
: not foundta/script.sh: 14: /usr/src/data/script.sh:
: not foundta/script.sh: 18: /usr/src/data/script.sh:
: not foundta/script.sh: 20: /usr/src/data/script.sh:

最佳答案

另一个问题可能是在“复制”命令之前放置了“WORKDIR”。
由于当前目录已更改为/ usr / src / myapp,并在./中复制搜索文件
如果您的dockerfile和脚本位于同一文件夹中,则只需将其命名为“COPY script.sh / usr / src / data”

关于docker - 无法使用ENTRYPOINT Docker运行script.sh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47414253/

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