gpt4 book ai didi

image - Docker:运行容器时在 docker 镜像中找不到文件 (bootstrap.sh)。虽然文件存在于图像中

转载 作者:行者123 更新时间:2023-12-01 01:40:41 27 4
gpt4 key购买 nike

我创建了一个图像来运行带有 chrome 的 docker 容器。下面是我的代码。我的 dockerfile 确实编译成图像。但是每当我尝试从镜像运行容器时,我都会收到错误“未找到 Bootstrap.sh 文件”,尽管文件存在于镜像内的 FileSystem 快照中。你可以检查截图。

请帮我解决这个问题,我是 docker 新手。

FROM ubuntu:16.04

RUN apt-get update && apt-get clean && apt-get install -y \
x11vnc \
xvfb \
fluxbox \
wmctrl \
wget \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update && apt-get -y install google-chrome-stable

RUN useradd apps \
&& mkdir -p /home/apps \
&& chown -v -R apps:apps /home/apps

COPY bootstrap.sh /

CMD '/bootstrap.sh'

BootStrap.sh 文件代码:
#!/bin/bash

# Based on: http://www.richud.com/wiki/Ubuntu_Fluxbox_GUI_with_x11vnc_and_Xvfb

main() {
log_i "Starting xvfb virtual display..."
launch_xvfb
log_i "Starting window manager..."
launch_window_manager
log_i "Starting VNC server..."
run_vnc_server
}

launch_xvfb() {
local xvfbLockFilePath="/tmp/.X1-lock"
if [ -f "${xvfbLockFilePath}" ]
then
log_i "Removing xvfb lock file '${xvfbLockFilePath}'..."
if ! rm -v "${xvfbLockFilePath}"
then
log_e "Failed to remove xvfb lock file"
exit 1
fi
fi

# Set defaults if the user did not specify envs.
export DISPLAY=${XVFB_DISPLAY:-:1}
local screen=${XVFB_SCREEN:-0}
local resolution=${XVFB_RESOLUTION:-1280x960x24}
local timeout=${XVFB_TIMEOUT:-5}

# Start and wait for either Xvfb to be fully up or we hit the timeout.
Xvfb ${DISPLAY} -screen ${screen} ${resolution} &
local loopCount=0
until xdpyinfo -display ${DISPLAY} > /dev/null 2>&1
do
loopCount=$((loopCount+1))
sleep 1
if [ ${loopCount} -gt ${timeout} ]
then
log_e "xvfb failed to start"
exit 1
fi
done
}

launch_window_manager() {
local timeout=${XVFB_TIMEOUT:-5}

# Start and wait for either fluxbox to be fully up or we hit the timeout.
fluxbox &
local loopCount=0
until wmctrl -m > /dev/null 2>&1
do
loopCount=$((loopCount+1))
sleep 1
if [ ${loopCount} -gt ${timeout} ]
then
log_e "fluxbox failed to start"
exit 1
fi
done
}

run_vnc_server() {
local passwordArgument='-nopw'

if [ -n "${VNC_SERVER_PASSWORD}" ]
then
local passwordFilePath="${HOME}/.x11vnc.pass"
if ! x11vnc -storepasswd "${VNC_SERVER_PASSWORD}" "${passwordFilePath}"
then
log_e "Failed to store x11vnc password"
exit 1
fi
passwordArgument=-"-rfbauth ${passwordFilePath}"
log_i "The VNC server will ask for a password"
else
log_w "The VNC server will NOT ask for a password"
fi

x11vnc -display ${DISPLAY} -forever ${passwordArgument} &
wait $!
}

log_i() {
log "[INFO] ${@}"
}

log_w() {
log "[WARN] ${@}"
}

log_e() {
log "[ERROR] ${@}"
}

log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] ${@}"
}

control_c() {
echo ""
exit
}

trap control_c SIGINT SIGTERM SIGHUP

main

exit

enter image description here
错误快照:
enter image description here
证明 bootstrap.sh 文件存在于我的 docker 镜像中

最佳答案

你需要做的是给文件正确的权限。如果可以在 Dockerfile 中添加行 RUN chmod +x /bootstrap.sh在运行 CMD 之前。

文件

FROM ubuntu:16.04

COPY bootstrap.sh /

RUN apt-get update && apt-get clean && apt-get install -y \
x11vnc \
xvfb \
fluxbox \
wmctrl \
wget \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
&& apt-get update && apt-get -y install google-chrome-stable

RUN useradd apps \
&& mkdir -p /home/apps \
&& chown -v -R apps:apps /home/apps


RUN chmod +x /bootstrap.sh

CMD '/bootstrap.sh'

关于image - Docker:运行容器时在 docker 镜像中找不到文件 (bootstrap.sh)。虽然文件存在于图像中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58026150/

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