This is my script:
#!/bin/bash
# some bash code here
And this is my Dockerfile:
FROM node:lts-bullseye-slim
COPY . .
RUN /Script.sh
And here's the error I get:
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
However, if I run the container in the interactive mode and enter it using docker exec -it container_name bash and run the script, it works.
I think it fails in the build process because Docker wants to use sh and not bash.
How can I force Docker to use bash, and not sh?
Update
This is my real script, and its real name is BuildScript and it has no extensions and it's in the root directory and it has 777 permission:
#!/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
And please don't tell me that you should add an extension, or not make 777 files, or not work in the root directory. Thank you.
/bin/sh -c /Script.shlike the error says, theshwill execute the script using its shebang, which uses bash, so I'd say the problem is in your script. Maybe you have DOS line endings or something. How are you running the script insidedocker exec -it container_name bash?RUNusingSHELL, or just doRUN bash /Script.shRUN bash /Script.shdid the trick. And it worked. The problem was not in my script file.RUN bash /scriptandRUN /scriptis the same as betweensh -c 'bash /script'andsh -c '/script'. They should both have worked if the script had been executable and had the correct#!line. Moving toRUN bash /scriptwould not by itself have made your issue go away. It is a pity that you don't show the script that generates the error.