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
433 stars 85 forks source link

Commit from container error vnc #131

Closed lmontagnon closed 8 months ago

lmontagnon commented 10 months ago

Hello and thanks for your job !

I have a question : when do you have finish with my container made from your image (tiryoh/ros2-desktop-vnc:humble) how to commit correctly my docker container with vnc ? because i have some issue when i commit and run the new image :

How to reproduce

  1. run build docker container of tiryoh/ros2-desktop-vnc:humble-amd64 docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64

  2. make some change inside it, stop it (ctrl+c) and commit the container docker commit 766f3e47cf4b lmontagnon/testimagevnc:v1

  3. Relaunch step 1. but with my new image lmontagnon/testimagevnc:v1 docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m lmontagnon/testimagevnc:v1

I'm using ubuntu 22.04 LTS and docker version 25.0.3

Thank you for your help,

lmontagnon

cardboardcode commented 8 months ago

Hi @lmontagnon, not the maintainer. Just a fellow user like you and I have at least managed to get it working.

Not exactly sure what the cause of the issue here is just based on the terminal output you have provided.

However, following the exact steps listed below got it working for me. Maybe you can give it a try and see if it works for you as well:

Environment :bookmark_tabs:

Steps To Reproduce :hammer:

1. Download repository:

cd $HOME
git clone https://github.com/Tiryoh/docker-ros2-desktop-vnc.git --depth 1 --single-branch

2. Build tiryoh/ros2-desktop-vnc:humble-amd64 docker image:

cd $HOME
cd docker-ros2-desktop-vnc/humble
docker buildx build --platform=linux/amd64 --progress=plain -t tiryoh/ros2-desktop-vnc:humble-amd64 .

3. Build docker container:

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

4. Access the docker VNC:

Open your preferred browser and go to http://127.0.0.1:6080/

Hope this helps. If it still doesn't, try posting the output of both the docker build and docker run in its entirety.

lmontagnon commented 8 months ago

Hi @cardboardcode ,

Thank you for your reply ! The build from source and run the container it's already working for me.

The problem is when I commit the container created once the work is finished inside and I want to relaunch this new image I get this error.

How to reproduce

  1. run build docker container of tiryoh/ros2-desktop-vnc:humble-amd64 docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64

  2. make some change inside it, stop it (ctrl+c) and commit the container docker commit 766f3e47cf4b lmontagnon/testimagevnc:v1

  3. Relaunch step 1. but with my new image lmontagnon/testimagevnc:v1 docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m lmontagnon/testimagevnc:v1

Can you try this and tell me if you have same issue ? I will add "How to reproduce" on my first comment.

cardboardcode commented 8 months ago

Hi @cardboardcode ,

Thank you for your reply ! The build from source and run the container it's already working for me.

The problem is when I commit the container created once the work is finished inside and I want to relaunch this new image I get this error.

How to reproduce

1. run build docker container of tiryoh/ros2-desktop-vnc:humble-amd64
   `docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64`

2. make some change inside it, stop it (ctrl+c) and commit the container
   `docker commit 766f3e47cf4b lmontagnon/testimagevnc:v1`

3. Relaunch **step 1.** but with my new image lmontagnon/testimagevnc:v1
   `docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m lmontagnon/testimagevnc:v1`

Can you try this and tell me if you have same issue ? I will add "How to reproduce" on my first comment.

Ah I get it now. Thank you @lmontagnon for clarifying further. Will try and update accordingly since I wish to do the same myself.

cardboardcode commented 8 months ago

Tried it. Encountered the same issue as original thread author.

Environment

Steps To Reproduce :hammer:

1. Download repository:

cd $HOME
git clone https://github.com/Tiryoh/docker-ros2-desktop-vnc.git --depth 1 --single-branch

2. Build tiryoh/ros2-desktop-vnc:humble-amd64 docker image:

cd $HOME
cd docker-ros2-desktop-vnc/humble
docker buildx build --platform=linux/amd64 --progress=plain -t tiryoh/ros2-desktop-vnc:humble-amd64 .

3. Build docker container:

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

4. Access the docker VNC and make new changes:

Open your preferred browser and go to http://127.0.0.1:6080/

Within VNC, open up terminal and run the following commands:

# Create a new .txt file on ~/Desktop
cd $HOME/Desktop
touch NEW_CHANGES.txt

5. Commit the new change to a new docker image:

docker commit <container_id> my_new_vnc_image:1

Determined the <container_id> by running docker container ls -a

6. Build docker container using new docker image:

docker run -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m my_new_vnc_image:1

Expected Behaviour :green_circle:

Able to run docker container and access VNC as per normal upon running Step 6. Should be able to see the NEW_CHANGES.txt file still present on Desktop.

Actual Behaviour :red_circle:

Encountered the following error upon running Step 6. Unable to access failing VNC docker container.

* enable custom user: ubuntu
useradd: user 'ubuntu' already exists
  set default password to "ubuntu"
source /opt/ros/humble/setup.bash
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.bash
============================================================================================
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-09 01:47:07,627 INFO Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2024-03-09 01:47:07,627 INFO Set uid to user 0 succeeded
2024-03-09 01:47:07,632 INFO RPC interface 'supervisor' initialized
2024-03-09 01:47:07,632 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2024-03-09 01:47:07,633 INFO supervisord started with pid 37
2024-03-09 01:47:08,638 INFO spawned: 'novnc' with pid 38
2024-03-09 01:47:08,644 INFO spawned: 'vnc' with pid 39
2024-03-09 01:47:08,946 INFO exited: vnc (exit status 1; not expected)
2024-03-09 01:47:09,988 INFO success: novnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-03-09 01:47:09,993 INFO spawned: 'vnc' with pid 64
2024-03-09 01:47:10,321 INFO exited: vnc (exit status 1; not expected)
2024-03-09 01:47:12,327 INFO spawned: 'vnc' with pid 73
2024-03-09 01:47:12,625 INFO exited: vnc (exit status 1; not expected)
2024-03-09 01:47:15,632 INFO spawned: 'vnc' with pid 82
2024-03-09 01:47:15,916 INFO exited: vnc (exit status 1; not expected)
2024-03-09 01:47:16,917 INFO gave up: vnc entered FATAL state, too many start retries too quickly

Remarks

Issue can be easily recreated. Will try and debug once I am free. Updating it here once I do.

cardboardcode commented 8 months ago

@lmontagnon Did a bit of debugging. Still can't determine the root cause but narrowed down the issue and figured out a dirty workaround.

Update

The cause of issue seems to be specifically due to:

Running the following command in line 350 of docker-ros2-desktop-vnc/humble/entrypoint.sh file:

exec /bin/tini -- supervisord -n -c /etc/supervisor/supervisord.conf

The program vnc fails when its command is ran in the supervisord.conf file:

[program:vnc]
command=gosu '$USER' bash '$VNCRUN_PATH'

Tried having the command run in verbose to give more info about the unexpected error causing vnc program to exit with status 1. However, for unknown reasons, it refuses to output in verbose mode so I am currently stuck at this stage of debugging.

Dirty Workaround :adhesive_bandage:

While I can't have supervisord in the docker container run in verbose mode, I found out that the same failing error does not occur when running the committed docker image manually.

You can follow the steps below to manually commit the docker container and run the VNC server based on the new docker image:

Instructions

  1. Modify line 350 docker-ros2-desktop-vnc/humble/entrypoint.sh file to the following:

    ...
    # exec /bin/tini -- supervisord -n -c /etc/supervisor/supervisord.conf
    /bin/bash
  2. Build the new docker image with the modified entrypoint.sh:

    docker buildx build --platform=linux/amd64 --progress=plain -t tiryoh/ros2-desktop-vnc:humble-amd64 .
  3. Build and run the docker container in interactive bash shell:

    docker run -it -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m tiryoh/ros2-desktop-vnc:humble-amd64
  4. Introduce a small change within the docker container:

    # Inside Docker Container
    cd /home/ubuntu/Desktop
    mkdir NEW_CHANGES.txt
  5. Commit docker container to new docker image:

    docker commit <container_id> my_new_image:1
  6. Build and run docker ccontainer based on new saved image in interactive bash shell

    docker run -it -p 6080:80 --security-opt seccomp=unconfined --shm-size=512m my_new_image:1
  7. Verify that the same changes is still present in the new container:

    # Within Docker Container
    ls /home/ubuntu/Desktop

    You should see NEW_CHANGES.txt file is still present.

  8. Run vnc program within the new docker container:

    gosu $USER bash $HOME/.vnc/vnc_run.sh -v
  9. Open a new terminal in your Host Machine and access the docker container:

    docker exec -it <container_id> bash
  10. Run novnc program within the new docker container:

    gosu $USER bash -c "websockify --web=/usr/lib/novnc 80 localhost:5901"
  11. Open your preferred browser and go to http://127.0.0.1:6080/

You should be able to access the VNC server now based on the new commited docker image.

Remarks :speech_balloon:

Still unable to deduce the root cause and have supervisord run in verbose mode. @Tiryoh Please advise on this issue. Also thank you for your hard work in this repository.

Tiryoh commented 8 months ago

Hi @cardboardcode @lmontagnon

Thanks for pointing this out! Sorry for my late responding, I have been away for a while for various reasons. I will check it out.

I'm still checking, but maybe this comment is relevant. https://github.com/Tiryoh/docker-ros2-desktop-vnc/issues/100#issuecomment-1646863650

cardboardcode commented 8 months ago

Hi @cardboardcode @lmontagnon

Thanks for pointing this out! Sorry for my late responding, I have been away for a while for various reasons. I will check it out.

I'm still checking, but maybe this comment is relevant. #100 (comment)

Hi @Tiryoh, no worries. Thank you for replying. :blush:

Will try logging out before stopping the container and update if this addresses the issue.

lmontagnon commented 8 months ago

Hi @cardboardcode , @Tiryoh ,

I tried logging out before commit and it seems to work! When I reproduce the same commands (step to reproduce) it works! Can you confirmed that @cardboardcode ?

Thanks for your help,

lmontagnon

cardboardcode commented 8 months ago

@Tiryoh @lmontagnon Can confirm that logging out before stopping the docker container and commiting to new docker image resolves this thread issue on my side as well.

Solution :sparkles:

Before stopping to commit docker container to new docker image, log out first.

Tiryoh commented 8 months ago

Hi @cardboardcode @lmontagnon

Great! Thank you for your research and thank you for sharing it with us!

Tiryoh commented 8 months ago

Hi @cardboardcode @lmontagnon

What do you think of adding the note like the following?

image
cardboardcode commented 8 months ago

@Tiryoh Not quite sure what is the purpose of the screenshot/note you attached above. Can you elaborate further?

For now, it is just a screenshot with information that the root README.md file already provided.

Tiryoh commented 8 months ago

@cardboardcode I made the earlier suggestion with the thought that a message on the console when "docker run" might tell the user that they need to log out before stopping to commit the docker container to a new docker image.

I am thinking of adding "docker commit instructions" to the README as well as the console message above until the issue is resolved.

image

cardboardcode commented 8 months ago

@cardboardcode I made the earlier suggestion with the thought that a message on the console when "docker run" might tell the user that they need to log out before stopping to commit the docker container to a new docker image.

I am thinking of adding "docker commit instructions" to the README as well as the console message above until the issue is resolved.

image

@Tiryoh Ah I see. Apologies. I didn't notice it the first time.

I think the NOTE 2 is helpful and important. Do leave it in as well as supplement the README.md as well. :relaxed: :+1:

Tiryoh commented 8 months ago

@cardboardcode Thanks a lot for getting back to me with your thoughts. Really appreciate it! 🙏

lmontagnon commented 8 months ago

@cardboardcode @Tiryoh

Thank you a lot for your help, @Tiryoh I think adding NOTE 2 it's very important and helpful too !

I have a new issue if you can help me ! https://github.com/Tiryoh/docker-ros2-desktop-vnc/issues/146

Best regards,

lmontagnon

JuAobo commented 6 months ago

@Tiryoh @lmontagnon Can confirm that logging out before stopping the docker container and commiting to new docker image resolves this thread issue on my side as well.

Solution

Before stopping to commit docker container to new docker image, log out first.

excuse me, could you explain how to logout?

edit: oh I got it. You mean by using the log out button from desktop

Tiryoh commented 6 months ago

You can logout from here image

SaadRana17 commented 5 months ago

Hi everyone, so before reaching to this thread I was facing same whenever I restart the container. It's seems that whenever we improperly shut down the container, vnc stucks.

Screenshot 2024-06-22 at 8 58 14 PM

I found two solutions for this.

1) Shut Down properly before you stop the container from Docker Desktop. Yes It's annoying as you have to wait for 60 seconds for shutting down.

Screenshot 2024-06-22 at 9 12 28 PM

2) However if you have accidentally closed the container and unable to start it, you can do as follows

https://github.com/Tiryoh/docker-ros2-desktop-vnc/assets/36335324/e9ebfa56-e698-4a5c-ac85-322f7ad12364

Enter below commands in Exec tab of that container

rm -f /tmp/.X1-lock
rm -f /tmp/.X11-unix/X1 

or you can connect to terminal of that container by it's ID

docker exec -it CONTAINER ID bash

and Enter above commands.

Tiryoh commented 5 months ago

Hi @SaadRana17,

Thank you for the detailed report! I'll check it out as well.