1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MacbookにDockerコンテナを立てて、ROSの亀さんを動かした(成功)

Last updated at Posted at 2021-08-18

今回、成功した画面

ブラウザ(Chrome)でlocalhostのポート6080番にアクセスした画面です。

Google先生に聞いてみると、MacbookにROSを入れるのは、すごく骨が折れるらしい・・・
なら、Docekrコンテナの中でUbuntuやCentOSを立ち上げて、ROSをLinux環境で動かそう、と思い立ちました。

Dockerコンテナの中から、Macbook(ホストマシン)のwebカメラにもアクセスできるみたいですし・・・。

事前準備

Docker for Macを入れる

( ダウンロード元 )

( 必要な理由 )

Dockerゲスト(コンテナ)OSにLinuxを利用したい場合、DockerホストOSはLinuxでなければならない。その為、Docker for MacではmacOS上に仮想マシンを用意し、その上に軽量のLinuxOSを動作させる。

Xquartzウィンドウを入れる

事前に、次のURLからdmgファイルをダウンロードして、Macbookにインストールしておきます。

MacbookでDockerコンテナを立ち上げて、その中でROSを動かす

写経したサイト

次のコマンドで、

Terminal
docker run -p 6080:80 --shm-size=512m tiryoh/ros-desktop-vnc:melodic

の中の__melodicディレクトリにあるDockerfile__をインストールしています。

スクリーンショット 2021-08-18 22.56.40.png

Dockerイメージを指定して、docker runします。

指定したDockerファイルがローカルに見つからないときは、DockerHubから、自動的に該当するDockerファイルがダウンロードされます。

ダウンロード後のインストールも、自動的に処理が走ります。

Terminal_1
electron@diynoMacBook-Pro ros_trial % docker run -p 6080:80 --shm-size=512m tiryoh/ros-desktop-vnc:melodic
Unable to find image 'tiryoh/ros-desktop-vnc:melodic' locally
melodic: Pulling from tiryoh/ros-desktop-vnc
35c102085707: Pull complete 
251f5509d51d: Pull complete 
8e829fe70a46: Pull complete 
6001e1789921: Pull complete 
7432864fac0c: Pull complete 
4de992ab98a9: Pull complete 
08271215cfa0: Pull complete 
f1fb1dbd1380: Pull complete 
ed3809743259: Pull complete 
9e198b6540f4: Pull complete 
2cd6eb7f26fb: Pull complete 
fa5ba08ad841: Pull complete 
14e9aa8f19d9: Pull complete 
eb94f3a4681c: Pull complete 
d07e2292d3d0: Pull complete 
a7945a9bb24c: Pull complete 
f9f7d34f4c45: Pull complete 
3db48f354a40: Pull complete 
653c655a715b: Pull complete 
Digest: sha256:8aa95c546a33bf0291b6162e3f5cdf1a0e958201ace3df63e58ae34cec77429e
Status: Downloaded newer image for tiryoh/ros-desktop-vnc:melodic
* enable custom user: ubuntu
useradd: user 'ubuntu' already exists
  set default password to "ubuntu"
2021-08-18 08:28:34,752 CRIT Supervisor running as root (no user in config file)
2021-08-18 08:28:34,752 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2021-08-18 08:28:34,770 INFO RPC interface 'supervisor' initialized
2021-08-18 08:28:34,770 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2021-08-18 08:28:34,770 INFO supervisord started with pid 19
2021-08-18 08:28:35,778 INFO spawned: 'nginx' with pid 22
2021-08-18 08:28:35,783 INFO spawned: 'web' with pid 23
2021-08-18 08:28:35,788 INFO spawned: 'novnc' with pid 24
2021-08-18 08:28:35,792 INFO spawned: 'wm' with pid 25
2021-08-18 08:28:35,795 INFO spawned: 'pcmanfm' with pid 26
2021-08-18 08:28:35,799 INFO spawned: 'lxpanel' with pid 27
2021-08-18 08:28:35,802 INFO spawned: 'xvfb' with pid 28
2021-08-18 08:28:35,805 INFO spawned: 'x11vnc' with pid 30
2021-08-18 08:28:36,135 INFO  Listening on http://localhost:6079 (run.py:87)
2021-08-18 08:28:36,872 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,872 INFO success: web entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,873 INFO success: novnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,873 INFO success: wm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,873 INFO success: pcmanfm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,873 INFO success: lxpanel entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,873 INFO success: xvfb entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:36,873 INFO success: x11vnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
>>> sending remote command: "qry=dpy_x,dpy_y" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:28:47] "GET /api/state?video=false&id=-1&w=1400&h=741 HTTP/1.0" 200 239 0.511778
2021-08-18 08:28:47,995 INFO waiting for xvfb to stop
2021-08-18 08:28:47,995 INFO waiting for wm to stop
2021-08-18 08:28:47,996 INFO waiting for pcmanfm to stop

Google ChoromeでLocalhostのポート6080を開く

http://127.0.0.1:6080/

次の画面が表示されます。

上の画面の中で、Consoleを2つ立ち上げて、それぞれ以下を入力します。

Localhostサーバ内にTerminal_①
$ roscore
Localhostサーバ内にTerminal_②
$ rosrun turtlesim turtlesim_node

( 1つ目のConsoleを立ち上げる )

  • __roscore__と入力

( 2つ目のConsoleを立ち上げる )

  • __rosrun turtlesim turtlesim_node__と入力

亀が表示された:eyes:

亀を動かしてみる

もう1つ、新たにConsoleを立ち上げて、次を入力。

Localhostサーバ内にTerminal_③
$ rosrun turtlesim turtle_teleop_key

新しいConsoleにカーソルをあえて、矢印キーを押すと、亀が上下左右に直線移動したり、頭の向きを変えることができました。

Macbookホスト側のTerminal 1の画面

Localhostのサーバ上で、亀を表示させたり、動かしてしている間、最初に立ち上げたMacbook(ホストマシン)側のTerminalでは、次の出力がひたすら表示されていました。

Terminal_1
2021-08-18 08:28:47,996 INFO waiting for lxpanel to stop
2021-08-18 08:28:47,997 INFO waiting for x11vnc to stop
2021-08-18 08:28:47,997 INFO waiting for novnc to stop
2021-08-18 08:28:47,999 INFO stopped: novnc (exit status 143)
2021-08-18 08:28:47,999 INFO stopped: lxpanel (terminated by SIGTERM)
2021-08-18 08:28:48,003 INFO stopped: xvfb (terminated by SIGKILL)
2021-08-18 08:28:48,004 INFO stopped: x11vnc (exit status 2)
2021-08-18 08:28:48,007 INFO stopped: wm (exit status 1)
2021-08-18 08:28:48,015 INFO stopped: pcmanfm (exit status 1)
2021-08-18 08:28:49,035 INFO spawned: 'xvfb' with pid 74
2021-08-18 08:28:49,040 INFO spawned: 'wm' with pid 75
2021-08-18 08:28:49,045 INFO spawned: 'pcmanfm' with pid 76
2021-08-18 08:28:49,049 INFO spawned: 'lxpanel' with pid 77
2021-08-18 08:28:49,053 INFO spawned: 'x11vnc' with pid 78
2021-08-18 08:28:49,059 INFO spawned: 'novnc' with pid 79
2021-08-18 08:28:50,082 INFO success: novnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:50,082 INFO success: wm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:50,082 INFO success: pcmanfm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:50,082 INFO success: lxpanel entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:50,082 INFO success: xvfb entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2021-08-18 08:28:50,082 INFO success: x11vnc entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
x:lxpanel: stopped
x:novnc: stopped
x:xvfb: stopped
x:wm: stopped
x:pcmanfm: stopped
x:x11vnc: stopped
x:xvfb: started
x:wm: started
x:pcmanfm: started
x:lxpanel: started
x:x11vnc: started
x:novnc: started
127.0.0.1 - - [2021-08-18 08:28:50] "GET /api/reset?video=false&id=-1&w=1400&h=741 HTTP/1.0" 200 140 2.459783
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
>>> sending remote command: "qry=dpy_x,dpy_y" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:28:51] "GET /api/state?video=false&id=1&w=1400&h=741 HTTP/1.0" 200 239 0.531455
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:28:53] "GET /api/state?video=false&id=4&w=1400&h=741 HTTP/1.0" 200 239 0.287734
127.0.0.1 - - [2021-08-18 08:29:04] "GET /api/health HTTP/1.1" 200 122 0.183075
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:29:24] "GET /api/state?video=false&id=5&w=839&h=741 HTTP/1.0" 200 239 30.229748
127.0.0.1 - - [2021-08-18 08:29:34] "GET /api/health HTTP/1.1" 200 122 0.169694
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:29:55] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.200947
127.0.0.1 - - [2021-08-18 08:30:05] "GET /api/health HTTP/1.1" 200 122 0.178263
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:30:26] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.216035
127.0.0.1 - - [2021-08-18 08:30:35] "GET /api/health HTTP/1.1" 200 122 0.177897
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:30:58] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.214221
127.0.0.1 - - [2021-08-18 08:31:05] "GET /api/health HTTP/1.1" 200 122 0.158584
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:31:29] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.205067
127.0.0.1 - - [2021-08-18 08:31:35] "GET /api/health HTTP/1.1" 200 122 0.159543
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:32:00] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.178062
127.0.0.1 - - [2021-08-18 08:32:06] "GET /api/health HTTP/1.1" 200 122 0.160322
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:32:31] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.265399
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:32:36] "GET /api/state?video=false&id=-1&w=1190&h=741 HTTP/1.0" 200 239 0.211221
127.0.0.1 - - [2021-08-18 08:32:36] "GET /api/health HTTP/1.1" 200 122 0.207611
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:33:02] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 128 30.213923
127.0.0.1 - - [2021-08-18 08:33:06] "GET /api/health HTTP/1.1" 200 122 0.156178
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:33:07] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.209387
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:33:19] "GET /api/state?video=false&id=-1&w=1190&h=741 HTTP/1.0" 200 239 0.226152
127.0.0.1 - - [2021-08-18 08:33:36] "GET /api/health HTTP/1.1" 200 122 0.162252
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:33:38] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 128 30.189854
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:33:41] "GET /api/state?video=false&id=-1&w=1190&h=741 HTTP/1.0" 200 239 0.227067
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:33:51] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 128 30.198149
127.0.0.1 - - [2021-08-18 08:34:07] "GET /api/health HTTP/1.1" 200 122 0.164621
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:34:12] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.205742
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:34:19] "GET /api/state?video=false&id=-1&w=1190&h=741 HTTP/1.0" 200 239 0.220297
127.0.0.1 - - [2021-08-18 08:34:37] "GET /api/health HTTP/1.1" 200 122 0.191775
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:34:44] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 128 30.189249
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:34:50] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.189194
127.0.0.1 - - [2021-08-18 08:35:07] "GET /api/health HTTP/1.1" 200 122 0.154795
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:35:21] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.213326
127.0.0.1 - - [2021-08-18 08:35:37] "GET /api/health HTTP/1.1" 200 122 0.163357
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:35:52] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.210971
127.0.0.1 - - [2021-08-18 08:36:08] "GET /api/health HTTP/1.1" 200 122 0.196519
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:36:09] "GET /api/state?video=false&id=-1&w=1190&h=741 HTTP/1.0" 200 239 0.294106
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:36:24] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 128 30.214486
127.0.0.1 - - [2021-08-18 08:36:38] "GET /api/health HTTP/1.1" 200 122 0.158128
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:36:40] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.195796
127.0.0.1 - - [2021-08-18 08:37:08] "GET /api/health HTTP/1.1" 200 122 0.176195
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:37:12] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.200822
127.0.0.1 - - [2021-08-18 08:37:38] "GET /api/health HTTP/1.1" 200 122 0.159262
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:37:43] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.210905
127.0.0.1 - - [2021-08-18 08:38:09] "GET /api/health HTTP/1.1" 200 122 0.175741
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:38:14] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 239 30.192055
127.0.0.1 - - [2021-08-18 08:38:39] "GET /api/health HTTP/1.1" 200 122 0.160104
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:38:45] "GET /api/state?video=false&id=-1&w=1368&h=741 HTTP/1.0" 200 239 0.219022
127.0.0.1 - - [2021-08-18 08:38:45] "GET /api/state?video=false&id=5&w=1190&h=741 HTTP/1.0" 200 128 30.186422
127.0.0.1 - - [2021-08-18 08:39:09] "GET /api/health HTTP/1.1" 200 122 0.177632
>>> sending remote command: "cmd=fb" via X11VNC_REMOTE X property.
127.0.0.1 - - [2021-08-18 08:39:16] "GET /api/state?video=false&id=5&w=1368&h=741 HTTP/1.0" 200 128 30.207504
^C2021-08-18 08:39:24,591 WARN received SIGINT indicating exit request
2021-08-18 08:39:24,595 INFO waiting for nginx, novnc, wm, pcmanfm, lxpanel, xvfb, x11vnc, web to die
2021-08-18 08:39:24,597 INFO stopped: novnc (exit status 143)
2021-08-18 08:39:24,602 INFO stopped: lxpanel (terminated by SIGTERM)
2021-08-18 08:39:24,605 INFO stopped: x11vnc (exit status 2)
2021-08-18 08:39:24,611 INFO stopped: xvfb (terminated by SIGKILL)
2021-08-18 08:39:24,611 INFO stopped: wm (exit status 1)
2021-08-18 08:39:24,620 INFO stopped: pcmanfm (exit status 1)
2021-08-18 08:39:24,626 INFO stopped: web (terminated by SIGTERM)
2021-08-18 08:39:24,634 WARN received SIGINT indicating exit request
2021-08-18 08:39:24,641 INFO stopped: nginx (exit status 0)
^C%

最後は、CTRL-Cで強制終了します。

DockerコンテナとDockerイメージの存在確認

Terminal electron@diynoMacBook-Pro ros_trial % pwd
/Users/electron/Desktop/ros_trial
electron@diynoMacBook-Pro ros_trial %
Terminal
electron@diynoMacBook-Pro ros_trial % docker ps             
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
electron@diynoMacBook-Pro ros_trial %
Terminal
electron@diynoMacBook-Pro ros_trial % docker ps -a
CONTAINER ID   IMAGE                            COMMAND                  CREATED             STATUS                         PORTS     NAMES
9320249f15fe   tiryoh/ros-desktop-vnc:melodic   "/startup.sh"            11 minutes ago      Exited (130) 24 seconds ago              sharp_poincare
b30406a3e289   3f860396e9a0                     "/ros_entrypoint.sh …"   26 minutes ago      Exited (137) 25 minutes ago              talker
1d401e3e03fc   3f860396e9a0                     "/ros_entrypoint.sh …"   26 minutes ago      Exited (0) 25 minutes ago                master
582497b6d3d6   3f860396e9a0                     "/ros_entrypoint.sh …"   26 minutes ago      Exited (137) 25 minutes ago              listener
f4a9a9de724c   centos:gahoh                     "/bin/bash"              About an hour ago   Exited (1) About an hour ago             centos7
b11252fc4c1e   jasonkwan/manim:latest           "/usr/bin/zsh"           7 months ago        Exited (0) 7 months ago                  elastic_shaw
electron@diynoMacBook-Pro ros_trial % 

Terminal
electron@diynoMacBook-Pro ros_trial % docker images
REPOSITORY                    TAG             IMAGE ID       CREATED             SIZE
ros-tutorials-2               latest          9850b837d8e0   20 minutes ago      1.18GB
ros                           ros-tutorials   3f860396e9a0   33 minutes ago      1.21GB
ros_test_listener             latest          3f860396e9a0   33 minutes ago      1.21GB
ros_test_master               latest          3f860396e9a0   33 minutes ago      1.21GB
ros_test_talker               latest          3f860396e9a0   33 minutes ago      1.21GB
centos                        gahoh           06e192b6b927   About an hour ago   736MB
tiryoh/ros-desktop-vnc        melodic         e717d0c4abe2   3 days ago          4.34GB
ros                           kinetic         a3c5711abb29   7 weeks ago         1.13GB
manimcommunity/manim          latest          805ff82b5b12   8 months ago        1.01GB
centos                        centos7         8652b9f0cb4c   9 months ago        204MB
jasonkwan/manim               latest          72bbfbf7c70d   13 months ago       2.77GB
ct2034/vnc-ros-kinetic-full   latest          0afed3f76def   18 months ago       4.24GB
electron@diynoMacBook-Pro ros_trial %

その他

なお、別のサイトを参考にしたところ、亀さんが登場するウィンドウを表示させるところで、つまづきました。

QXcbConnection: Could not connect to display ローカルホストのIPアドレス:ポート番号

このエラー、同じくROSを実行しようとして直面した次の方は、トラブルシュートできたとか。残念ながら、解決法が描かれたサイトがリンク切れしていました。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?