我有一个泊坞窗文件,该文件应该在ENTRYPOINT中运行shell脚本,但似乎代码未运行。
我尝试使用#!/ bin / sh,#!/ bin / bash或完全删除的shebang进行游戏,如此处所述:Stackoverflow。我还使用了ENTRYPOINT或CMD。此外,我使用dos2unix转换了unix中的每个文件,但每次都得到相同的结果。
该图像在一个由Dockerfile构建的无业游民的文件中调用
config.vm.provision "docker" do |d|
d.build_image "/vagrant",
args: "-t keycloak-image"
d.run "keycloak",
image: "keycloak-image:latest",
args: "-p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e DB_VENDOR=H2"
end
这是当前的Dockerfile
FROM jboss/keycloak:latest
USER root
# copy from /setup into /opt/jboss/setup
COPY /setup /opt/jboss/setup
#use opt/jboss/setup as working directory
WORKDIR /opt/jboss/setup
#take he run and load script and convert it to a unix script by deleting /r with the tr pipe and -d (delete)
RUN cat /opt/jboss/setup/run.sh | tr -d '\r' > /opt/jboss/setup/run.sh
RUN cat /opt/jboss/setup/load.sh | tr -d '\r' > /opt/jboss/setup/load.sh
ENTRYPOINT ["sh","./run.sh"]
和当前的shell脚本
#!/bin/sh
function is_keycloak_running {
local http_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${KEYCLOAK_PORT}/auth/admin/realms)
if [[ $http_code -eq 401 ]]; then
return 0
else
return 1
fi
}
function configure_keycloak {
until is_keycloak_running; do
echo Keycloak still not running, waiting 5 seconds
sleep 5
done
echo Keycloak is running, proceeding with configuration
echo Now run load script inside run script
./load.sh
}
if [ ! -f ${JBOSS_HOME}/standalone/data/docker-container-configuration-done ]; then
touch ${JBOSS_HOME}/standalone/data/docker-container-configuration-done
configure_keycloak &
fi
# this is not in a volume, at least not by default, so we need to replace the port every time the server runs
sed -i -e 's/<socket-binding name="http".*/<socket-binding name="http" port="'$KEYCLOAK_PORT'"\/>/' ${JBOSS_HOME}/standalone/configuration/standalone.xml
${JBOSS_HOME}/bin/add-user-keycloak.sh --user $KEYCLOAK_USER --password $KEYCLOAK_PASSWORD
${JBOSS_HOME}/bin/standalone.sh -b 0.0.0.0
输出
==> default: Step 2/7 : USER root
==> default: ---> Running in 3505173391f1
==> default: Removing intermediate container 3505173391f1
==> default: ---> c92194427482
==> default: Step 3/7 : COPY /setup /opt/jboss/setup
==> default: ---> faea269e6649
==> default: Step 4/7 : WORKDIR /opt/jboss/setup
==> default: ---> Running in db7ad91dba9e
==> default: Removing intermediate container db7ad91dba9e
==> default: ---> 3554249590b1
==> default: Step 5/7 : RUN cat /opt/jboss/setup/run.sh | tr -d '\r' > /opt/jboss/setup/run.sh
==> default: ---> Running in 20f8569e305d
==> default: Removing intermediate container 20f8569e305d
==> default: ---> 16b5d0c7a147
==> default: Step 6/7 : RUN cat /opt/jboss/setup/load.sh | tr -d '\r' > /opt/jboss/setup/load.sh
==> default: ---> Running in 0fc35b4e9d51
==> default: Removing intermediate container 0fc35b4e9d51
==> default: ---> 6e7f159029b0
==> default: Step 7/7 : CMD ["sh","./run.sh"]
==> default: ---> Running in f1209cc305e3
==> default: Removing intermediate container f1209cc305e3
==> default: ---> ed9f8dd4cc22
==> default: Successfully built ed9f8dd4cc22
==> default: Successfully tagged keycloak-image:latest
==> default: Starting Docker containers...
==> default: -- Container: keycloak
如您所见,输出中没有回声。此外,该程序未在localhost:8080上运行,但是如果我删除ENTRYPOINT,则该程序可用。因此,该脚本不起作用,有人知道吗?
感谢您的帮助
Matthias