Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to run command in docker container?? #232

Closed
jeprince opened this issue Mar 18, 2020 · 9 comments
Closed

Question: How to run command in docker container?? #232

jeprince opened this issue Mar 18, 2020 · 9 comments
Labels

Comments

@jeprince
Copy link

I know its probably super obvious but i've tried everything.... I created a docker image (i can provide the dockerfile if needed), and i want to start the container from that image and run a command that starts a server and opens a gui application (gazebo).

I want to run this command:
cd /home/user/Firmware;make px4_sitl_default gazebo

I've tried:

x11docker --gpu --size "1400x1050" --no-entrypoint -- -- px4/gazebo:init ["cd /home/user/Firmware;make px4_sitl_default

x11docker --gpu --size "1400x1050" --runasroot="cd /home/user/Firmware;make px4_sitl_default gazebo" -- -- px4/gazebo:init 

I've tried variations of the above settings. The closest ive gotten is this error (labuser is my host's username, the file path /home/user.... is on the container:

/usr/local/bin/entrypoint.sh: line 20: /fakehome/labuser/[bash;/home/user/Firmware;make px4_sitl_default gazebo]: No such file or directory

@mviereck
Copy link
Owner

mviereck commented Mar 18, 2020

Try:

x11docker --gpu --size "1400x1050" --workdir  "/home/user/Firmware" -- px4/gazebo:init make px4_sitl_default gazebo

Is make px4_sitl_default gazebo one, two or three commands?
Maybe you need:

x11docker --gpu --size "1400x1050" --workdir  "/home/user/Firmware" -- px4/gazebo:init sh -c 'make px4_sitl_default; gazebo'

@jeprince
Copy link
Author

make px4_sitl_default gazebo is one command. Its calls a makefile that starts a SITL (software in the loop) flight controller (FCU) for a drone, and start gazebo with this simulated FCU loaded in.

I ran the commands above and got this:

[labuser@localhost ~]$ x11docker --gpu --size "1400x1050" --workdir  "/home/user/Firmware" -- px4/gazebo:init sh -c 'make px4_sitl_default; gazebo'

x11docker ERROR: /usr/bin/x11docker: unrecognized option '--workdir'

  Type 'x11docker --help' for usage information
  Debug options: '--verbose' (full log) or '--debug' (log excerpt).
  Logfile will be: 
  Please report issues at https://github.com/mviereck/x11docker

I then tried sudo x11docker --update and tried again, no luck.

@mviereck
Copy link
Owner

x11docker ERROR: /usr/bin/x11docker: unrecognized option '--workdir'
I then tried sudo x11docker --update and tried again, no luck.

ouch!
Is fixed now in v6.6.0, please run x11docker --update again.

@jeprince
Copy link
Author

jeprince commented Mar 20, 2020

command that ended up working for me:
x11docker --name="gazebo_gui" --gpu --size="1400x1050" --home="/home/labuser/Documents/templates/" --workdir="/home/user/Firmware" --user="root" -- -- px4/gazebo:init bash -c 'gazebo --verbose'"

Thanks! i got the application, gazebo, to launch now but something weird is going on. It crashes when i start another program on the same container that hosts a server on port 14560/tcp (make px4_sitl_default none_iris). I think it may have something to do with the docker network connection

Is there a way to set which docker network to connect to? Default is the host bridge connection but I have a custom bridge connection for my other containers that the x11docker gazebo container needs to communicate with (all the other containers are hosting different instances of the same server on port 14560/tcp that gazebo needs to connect to. I think that may be why it is crashing.

@mviereck
Copy link
Owner

I am not experienced in network setups, but basically I see two ways.
You need to add a docker option to the x11docker command between the two -- --, maybe -- -p 14560:14560 --.
Or you need to specify a network with -- --network=YOURNETWORK --.
How do you set up the network for your other containers?

@jeprince
Copy link
Author

jeprince commented Mar 21, 2020

Thanks, I wasn't sure where the network command went. The network command works but i've noticed that the command after px4/gazebo:init bash -c is executed twice. I can tell because i see this output in the terminal:

..................
x11docker note: Failed to add container user to group render.

Gazebo multi-robot simulator, version 9.0.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org

Gazebo multi-robot simulator, version 9.0.0
Copyright (C) 2012 Open Source Robotics Foundation.
Released under the Apache 2 License.
http://gazebosim.org
..................

I think two instances of the command gazebo /root/worlds/world.world --verbose are executed and it tries to bind to the same port. Any clue why this would execute twice?

px4/gazebo:init bash -c 'gazebo --verbose' works just fine because it does not load a world file with plugins, or try to bind to a port

edit:

turns out it was not executing twice. Error i was getting was this:

[gazebo_mavlink_interface.cpp:576] bind failed: Cannot assign requested address, aborting

@mviereck
Copy link
Owner

i've noticed that the command after px4/gazebo:init bash -c is executed twice.

That's odd. Maybe your image has a custom entrypoint that could cause this behaviour? Try with --no-entrypoint. If the issue persists, please provide me ~/.cache/x11docker/x11docker.log at www.pastebin.com.

Btw, it should work if you run -- px4/gazebo:init gazebo --verbose instead of -- px4/gazebo:init bash -c 'gazebo --verbose' . The bash -c '' way is just helpful to run multiple commands.

@jeprince
Copy link
Author

I got it working. I had to use checkout v1.8.2 from PX4/Firmware,not the latest v1.9.0. The problem was not with x11docker but thanks for helping with this, i'm going to try to run my code on windows now...

@mviereck
Copy link
Owner

I got it working.

Great!

i'm going to try to run my code on windows now...

If you'll have issues on Windows, please open a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants