Docker가 sh 대신 bash를 사용하여 스크립트를 실행하도록 하려면 어떻게 해야 하나요?

Docker가 sh 대신 bash를 사용하여 스크립트를 실행하도록 하려면 어떻게 해야 하나요?

이것은 내 스크립트입니다.

#!/bin/bash

# some bash code here

이 내 꺼야 Dockerfile:

FROM node:lts-bullseye-slim
COPY . .
RUN /Script.sh

내가 얻는 오류는 다음과 같습니다.

Step 5/5 : RUN /Script.sh
 ---> Running in 09bbdebbc3d7
/Script.sh: line 25: syntax error: unexpected end of file
The command '/bin/sh -c /Script.sh' returned a non-zero code: 2

그러나 대화형 모드에서 컨테이너를 실행하고 docker exec -it container_name bash스크립트를 사용하여 입력하고 실행하면 작동합니다.

Docker shbash.

Docker가 sh 대신 bash를 사용하도록 강제하는 방법은 무엇입니까?

고쳐 쓰다

이것은 내 실제 스크립트입니다. 실제 이름은 이고 BuildScript확장자가 없으며 루트 디렉터리에 있으며 777 권한이 있습니다.

#!/bin/bash

function RemoveDevelopmentItems()
{
    echo "Removing development items ..."
    rm -rf ${RepositoryPath}/Host
}

function BuildDirectories()
{
    echo "Building directories ..."
    mkdir -p ${RepositoryPath}/src
    mkdir -p ${RepositoryPath}/public
    mkdir -p ${RepositoryPath}/public/favicons
    mkdir -p ${RepositoryPath}/public/Fonts
    mkdir -p ${RepositoryPath}/src/Base
    mkdir -p ${RepositoryPath}/src/Contexts
    mkdir -p ${RepositoryPath}/src/Components
    mkdir -p ${RepositoryPath}/src/Hooks
    mkdir -p ${RepositoryPath}/src/Panel
}

function CopyCommon()
{
    echo "Copying common ..."
    cp -a /${Organization}/Common/Branding/Favicons/* ${RepositoryPath}/public/favicons
    cp -r /${Organization}/Common/Branding ${RepositoryPath}/src/Branding
    cp -r /${Organization}/Common/Logo.jsx ${RepositoryPath}/src/Logo.jsx
}

function CopyBase()
{
    echo "Copying base ..."
    cp -r /HolismPanel/Infra/src/Base ${RepositoryPath}/src
    cp -r /HolismPanel/Infra/src/Components ${RepositoryPath}/src
    cp -r /HolismPanel/Infra/src/Contexts ${RepositoryPath}/src
    cp -r /HolismPanel/Infra/src/Fonts ${RepositoryPath}/public
    cp -r /HolismPanel/Infra/src/Hooks ${RepositoryPath}/src
    cp -r /HolismPanel/Infra/src/Panel ${RepositoryPath}/src
    cp /HolismPanel/Infra/index.html ${RepositoryPath}/index.html
    cp /HolismPanel/Infra/package.json ${RepositoryPath}
    cp /HolismPanel/Infra/postcss.config.js ${RepositoryPath}
    cp /HolismPanel/Infra/src/index.css ${RepositoryPath}/src
    cp /HolismPanel/Infra/src/main.jsx ${RepositoryPath}/src
    cp /HolismPanel/Infra/tailwind.config.js ${RepositoryPath}
    cp /HolismPanel/Infra/vite.config.js ${RepositoryPath}
}

function CopyDependencies()
{
    echo "Copying dependencies ..."
    find /HolismPanel -mindepth 1 -maxdepth 1 -not -name Infra |
    while read DependencyPath;
    do
        DependencyName=$(basename $DependencyPath);
        if [[ ${Repository} == *Admin* ]]; then
            mkdir -p ${RepositoryPath}/src/$DependencyName
            cp -a /HolismPanel/$DependencyName/Admin/* ${RepositoryPath}/src/$DependencyName
        fi
    done
}

function MoveMainRepoFiles()
{
    echo "Moving main repo files ..."
    mv ${RepositoryPath}/Menu.jsx ${RepositoryPath}/src/Menu.jsx
    mv ${RepositoryPath}/Routes.jsx ${RepositoryPath}/src/Routes.jsx
    mv ${RepositoryPath}/HeaderActions.jsx ${RepositoryPath}/src/HeaderActions.jsx
    find ${RepositoryPath} -mindepth 1 -maxdepth 1 -type d -not -name src -not -name public |
    while read MainRepoDirectory;
    do
        mv $MainRepoDirectory ${RepositoryPath}/src
    done
}

function LinkNodeModules()
{
    echo "Linking node_modules ..."
    ln -s /HolismPanel/Infra/node_modules ${RepositoryPath}
}

RemoveDevelopmentItems
BuildDirectories
CopyCommon
CopyBase
CopyDependencies
MoveMainRepoFiles
LinkNodeModules

그리고 확장을 추가해야 한다거나, 777 파일을 생성하지 말아야 한다거나, 루트 디렉터리에서 작업하지 말아야 한다고 말하지 마세요. 감사해요.

답변1

RUN /Script.shRUN실행할 명령의 셸 형식입니다 /bin/sh -c <command>. 스크립트를 직접 실행하려면 다음을 사용하세요.구현하다배열 형식을 다음으로 변경합니다 RUN ["/Script.sh"]. 스크립트가 실행 가능한지 확인합니다(실행 chmod +x Script.sh). 또한 루트 디렉터리를 작업 디렉터리로 사용하지 마십시오.

관련 정보