【问题标题】:Docker: File (bootstrap.sh) not found in docker image while running container. Although file is present in imageDocker:运行容器时在 Docker 映像中找不到文件 (bootstrap.sh)。虽然文件存在于图像中
【发布时间】:2019-09-20 10:03:01
【问题描述】:

我创建了一个镜像来运行带有 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

错误快照: 证明 bootstrap.sh 文件存在于我的 docker 映像中

【问题讨论】:

  • docker run -it your_image "/bootstrap.sh"
  • 我试过但得到这个错误“docker:来自守护进程的错误响应:OCI 运行时创建失败:container_linux.go:345:启动容器进程导致“exec:\”bootstrap.sh\”:可执行文件在 $PATH 中找不到“:未知。”
  • docker build --no-cache -t your_image . 似乎窗口解释了路径磨损,尝试docker run -it your_image "\bootstrap.sh"
  • ` \"bootstrap.sh\":` 它应该像` \bootstrap.sh":
  • 或者尝试在 gitbash 中运行命令

标签: image docker containers devops


【解决方案1】:

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

Dockerfile

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' 

【讨论】:

  • 试试我提供的 Dockerfile,它绝对适合我。自己跑了。
  • 输出:``` daudnadeem:mock_the_proc daudn$ docker run bootstrap [2019-09-20 10:28:26] [INFO] 开始 xvfb 虚拟显示... [2019-09-20 10 :28:26] [INFO] 启动窗口管理器... 读取失败:session.ignoreBorder 设置默认值 读取失败:session.forcePseudoTransparency 设置默认值 读取失败:session.colorsPerChannel 设置默认值 读取失败:会话。 doubleClickInterval 设置默认值 读取失败:session.tabPadding 设置默认值 读取失败:session.styleOverlay 设置默认值```
  • 非常感谢。问题解决了。添加“RUN chmod +x /bootstrap.sh”后,我需要为 bootstrap.sh 文件设置 linux 行结尾,方法是在 notepadd++ 中将 \r\n 替换为 \n 并使用扩展搜索模式来解决我的问题。
【解决方案2】:

你可以试试这个: CMD sh /bootstrap.sh

Docker 文件

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


CMD sh /bootstrap.sh 


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 2019-06-26
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多