4

I have created an image to run docker container with chrome. Below is my code. My dockerfile does compile into image. But whenever I try to run container from image I get error "Bootstrap.sh file not found" Although file is present in my FileSystem snapshot inside image. You can check screenshot.

Please help me resolve this issue I am new to 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 file code:

#!/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 Snapshot of Error: enter image description here Proof bootstrap.sh file is present inside my docker image

Umar Tahir
  • 585
  • 6
  • 21
  • `docker run -it your_image "/bootstrap.sh"` – Adiii Sep 20 '19 at 10:23
  • I tried but got this error "docker: Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"bootstrap.sh\": executable file not found in $PATH": unknown." – Umar Tahir Sep 20 '19 at 10:29
  • `docker build --no-cache -t your_image .` and seems like window interpret the path worng , try `docker run -it your_image "\bootstrap.sh"` – Adiii Sep 20 '19 at 10:31
  • ` \"bootstrap.sh\":` it should be like ` \bootstrap.sh": – Adiii Sep 20 '19 at 10:32
  • or try to run command in gitbash – Adiii Sep 20 '19 at 11:33

3 Answers3

3

What you need to do is give the file the correct permissions. In your Dockerfile if you can add the line RUN chmod +x /bootstrap.sh right before you run CMD.

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' 
DUDANF
  • 2,618
  • 1
  • 12
  • 42
  • Try the Dockerfile I provided, it definitely works for me. Just ran it myself. – DUDANF Sep 20 '19 at 10:29
  • Output: ``` daudnadeem:mock_the_proc daudn$ docker run bootstrap [2019-09-20 10:28:26] [INFO] Starting xvfb virtual display... [2019-09-20 10:28:26] [INFO] Starting window manager... Failed to read: session.ignoreBorder Setting default value Failed to read: session.forcePseudoTransparency Setting default value Failed to read: session.colorsPerChannel Setting default value Failed to read: session.doubleClickInterval Setting default value Failed to read: session.tabPadding Setting default value Failed to read: session.styleOverlay Setting default value ``` – DUDANF Sep 20 '19 at 10:30
  • 4
    Thank you very much. Problem solved. After adding "RUN chmod +x /bootstrap.sh" I needed to set linux line endings for bootstrap.sh file by replacing \r\n with \n in notepadd++ with extended search mode in order to solve my problem. – Umar Tahir Sep 20 '19 at 13:21
1

You can try this: CMD sh /bootstrap.sh

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


CMD sh /bootstrap.sh 


Awais
  • 33
  • 7
0

For me the fix was changing #!/bin/bash for #!/bin/sh

I think it would depend on the image you are using. If it uses bash or sh for running a script with CMD.

Info about the difference: Difference between sh and Bash

Martin Schaer
  • 3,986
  • 1
  • 23
  • 28