Tiryoh / docker-ros2-desktop-vnc

🐳 Dockerfiles to provide HTML5 VNC interface to access Ubuntu Desktop + ROS 2
https://memoteki.net/archives/2955
Apache License 2.0
432 stars 85 forks source link

/bin/bash: /entrypoint.sh: /bin/bash^M: bad interpreter: No such file or directory - Unable to run on Windows 10 #147

Closed cardboardcode closed 8 months ago

cardboardcode commented 8 months ago

Issue Description :bug:

Kept encountering the following error output upon running the docker container for ROS 2 Humble using the command below in Windows 10:

Command

docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble

Error :warning:

/bin/bash: /entrypoint.sh: /bin/bash^M: bad interpreter: No such file or directory

Environment :books:

  1. Microsoft Windows 10 Home - 10.0.19045 N/A Build 19045
  2. Docker - 25.0.3

Steps To Reproduce :hammer:

Please follow the instructions below to recreate the issue highlighted:

  1. Download the repository

    cd %USERPROFILE%/Downloads
    git clone https://github.com/Tiryoh/docker-ros2-desktop-vnc.git --depth 1
  2. Build the docker image:

    cd %USERPROFILE%/Downloads/docker-ros2-desktop-vnc/humble
    docker build -t tiryoh/ros2-desktop-vnc:humble .
  3. Build and run the docker container from docker image:

    docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble

Expected Behaviour :green_circle:

The command prompt terminal should output a similar output as below:

* enable custom user: ubuntu
  set default password to "ubuntu"
============================================================================================
NOTE: --security-opt seccomp=unconfined flag is required to launch Ubuntu Jammy based image.
See https://github.com/Tiryoh/docker-ros2-desktop-vnc/pull/56
============================================================================================
2024-03-25 01:53:27,095 INFO Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2024-03-25 01:53:27,096 INFO Set uid to user 0 succeeded
2024-03-25 01:53:27,098 INFO RPC interface 'supervisor' initialized
2024-03-25 01:53:27,099 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2024-03-25 01:53:27,100 INFO supervisord started with pid 44
2024-03-25 01:53:28,102 INFO spawned: 'novnc' with pid 45
2024-03-25 01:53:28,105 INFO spawned: 'vnc' with pid 46
2024-03-25 01:53:29,316 INFO success: novnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-03-25 01:53:29,316 INFO success: vnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

Actual Behaviour :red_circle:

Docker container fails to build and run, giving the aforementioned error:

/bin/bash: /entrypoint.sh: /bin/bash^M: bad interpreter: No such file or directory

Rough Workaround :adhesive_bandage:

Make sure that the humble/entrypoint.sh is indented with LF, instead of CRLF. See this article below for more details as to why there is a difference between CRLF and LF, pertaining to different operating systems:

https://dhwaneetbhatt.com/blog/why-crlf-vs-lf/

  1. Open the file humble/entrypoint.sh in your preferred text editor. Search for a setting to convert line ending character from CRLF to LF.

Eg. I used Visual Studio 2019 and it is found on the bottom right as shown below: image

  1. Once you have the above, rebuild the docker image to load the new entrypoint.sh:
cd %USERPROFILE%/Downloads/docker-ros2-desktop-vnc/humble
docker build -t tiryoh/ros2-desktop-vnc:humble .
  1. Build and run the new docker container from new image:
docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble

Remarks :speech_balloon:

Going to try and figure out a long term solution since it is slightly annoying to do the Rough Workaround every time. Will update here accordingly once I have done so.

cardboardcode commented 8 months ago

Progress Update :speech_balloon:

In terms of a long-term solution, it seems to be installing and running dos2unix command within the Dockerfile before running it as a container.

This can be done so by modifying line no. 46 in /humble/Dockerfile like so:

 RUN apt-get update && \
         tigervnc-standalone-server tigervnc-common \
         supervisor wget curl gosu git sudo python3-pip tini \
         build-essential vim sudo lsb-release locales \
         bash-completion tzdata terminator \
         dos2unix && \

Also modify line no. 120 in /humble/Dockerfile like so:

 COPY ./entrypoint.sh /
 RUN dos2unix /entrypoint.sh
 ENTRYPOINT [ "/bin/bash", "-c", "/entrypoint.sh" ]

Doing so makes sure that entrypoint.sh is using LF when loaded into the docker image.

Remarks :speech_balloon:

Will try and run the same modification for a Linux host and see if it still works. If it still works, will update here and attempt to make a pull request to introduce the change for all.

cardboardcode commented 8 months ago

Progress Update :speech_balloon:

Verified that the modified Dockerfile above still works from a Linux host. The new Dockerfile for ROS 2 Humble now looks like below:

Click here for new Dockerfile ```bash # Copyright 2020-2023 Tiryoh # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # This Dockerfile is based on https://github.com/AtsushiSaito/docker-ubuntu-sweb # which is released under the Apache-2.0 license. FROM ubuntu:jammy-20240227 ARG TARGETPLATFORM LABEL maintainer="Tiryoh" SHELL ["/bin/bash", "-c"] # Upgrade OS RUN apt-get update -q && \ DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \ apt-get autoclean && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* # Install Ubuntu Mate desktop RUN apt-get update -q && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ ubuntu-mate-desktop && \ apt-get autoclean && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* # Add Package RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ tigervnc-standalone-server tigervnc-common \ supervisor wget curl gosu git sudo python3-pip tini \ build-essential vim sudo lsb-release locales \ bash-completion tzdata terminator \ dos2unix && \ apt-get autoclean && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* # noVNC and Websockify RUN git clone https://github.com/AtsushiSaito/noVNC.git -b add_clipboard_support /usr/lib/novnc RUN pip install git+https://github.com/novnc/websockify.git@v0.10.0 RUN ln -s /usr/lib/novnc/vnc.html /usr/lib/novnc/index.html # Set remote resize function enabled by default RUN sed -i "s/UI.initSetting('resize', 'off');/UI.initSetting('resize', 'remote');/g" /usr/lib/novnc/app/ui.js # Disable auto update and crash report RUN sed -i 's/Prompt=.*/Prompt=never/' /etc/update-manager/release-upgrades RUN sed -i 's/enabled=1/enabled=0/g' /etc/default/apport # Enable apt-get completion RUN rm /etc/apt/apt.conf.d/docker-clean # Install Firefox RUN DEBIAN_FRONTEND=noninteractive add-apt-repository ppa:mozillateam/ppa -y && \ echo 'Package: *' > /etc/apt/preferences.d/mozilla-firefox && \ echo 'Pin: release o=LP-PPA-mozillateam' >> /etc/apt/preferences.d/mozilla-firefox && \ echo 'Pin-Priority: 1001' >> /etc/apt/preferences.d/mozilla-firefox && \ apt-get update -q && \ apt-get install -y \ firefox && \ apt-get autoclean && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* # Install VSCodium RUN wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg \ | gpg --dearmor \ | dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg && \ echo 'deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] https://download.vscodium.com/debs vscodium main' \ | tee /etc/apt/sources.list.d/vscodium.list && \ apt-get update -q && \ apt-get install -y codium && \ apt-get autoclean && \ apt-get autoremove && \ rm -rf /var/lib/apt/lists/* # Install ROS ENV ROS_DISTRO humble # desktop or ros-base ARG INSTALL_PACKAGE=desktop RUN apt-get update -q && \ apt-get install -y curl gnupg2 lsb-release && \ curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg && \ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/ros2.list > /dev/null && \ apt-get update -q && \ apt-get install -y ros-${ROS_DISTRO}-${INSTALL_PACKAGE} \ python3-argcomplete \ python3-colcon-common-extensions \ python3-rosdep python3-vcstool && \ rosdep init && \ rm -rf /var/lib/apt/lists/* RUN rosdep update # Install simulation package only on amd64 # Not ready for arm64 for now (July 28th, 2020) # https://github.com/Tiryoh/docker-ros2-desktop-vnc/pull/56#issuecomment-1196359860 RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ apt-get update -q && \ apt-get install -y \ ros-${ROS_DISTRO}-gazebo-ros-pkgs \ ros-${ROS_DISTRO}-ros-ign && \ rm -rf /var/lib/apt/lists/*; \ fi COPY ./entrypoint.sh / RUN dos2unix /entrypoint.sh ENTRYPOINT [ "/bin/bash", "-c", "/entrypoint.sh" ] ENV USER ubuntu ENV PASSWD ubuntu ```

@Tiryoh Would it be okay if I introduced dos2unix as a dependency within Dockerfile for ROS 2 Humble in a pull request?

Tiryoh commented 8 months ago

Hi @cardboardcode, Thanks for the detailed report! Your suggestion sounds reasonable to me. Could you create a pull request?