Elixir 学習用
```bash
$ docker compose up --build
...
Attaching to livebook
livebook | [Livebook] Application running at http://localhost:8080/?token=xxxxx表示される URL にアクセスする
Apple Silicon の場合、 SQL Server を使用するために Rosetta を使用する必要がある
/usr/sbin/softwareupdate --install-rosetta --agree-to-licenseRancher Desktop の設定
Preferences>Virtual Machine>EmulationをVZに設定するPreferences>Virtual Machine>Volumesをvirtiofsに設定する
コンテナを起動する
$ docker compose -f docker-compose.with-db.yml up --build
...
postgres_for_livebook | 2023-10-30 11:47:54.930 UTC [1] LOG: database system is ready to accept connections
...
livebook_with_db | [Livebook] Application running at http://localhost:8080/?token=xxxxx表示される URL にアクセスする
$ docker compose -f docker-compose.with-neo4j.yml up --build
...
postgres_for_livebook | 2023-10-30 11:47:54.930 UTC [1] LOG: database system is ready to accept connections
...
livebook_with_db | [Livebook] Application running at http://localhost:8080/?token=xxxxx表示される URL にアクセスする
Neo4j Browser には http://localhost:7474 でアクセスできる
$ docker compose -f docker-compose.with-falkor-db.yml up --build
...
postgres_for_livebook | 2023-10-30 11:47:54.930 UTC [1] LOG: database system is ready to accept connections
...
livebook_with_db | [Livebook] Application running at http://localhost:8080/?token=xxxxx表示される URL にアクセスする
FalkorDB Browser には http://localhost:3000 でアクセスできる
Charms を使用する場合、以下のコマンドでコンテナを起動する
ただし、 Apple Sillicon 以外には対応していない
$ docker compose -f docker-compose.charms.yml up --build
...
livebook_charms | [Livebook] Application running at http://localhost:8080/?token=xxxxx表示される URL にアクセスする
コンテナを起動している状態で以下のコマンドを実行する
docker export elixir-learning-livebook-1 -o elixir.tar.gz実行する Windows マシンの PowerShell で以下のコマンドを実行する
※ WSL2 導入済とする
wsl --import elixir $env:userprofile\AppData\elixir elixir.tar.gz実行する Windows マシンの PowerShell で以下のコマンドを実行する
wsl -d elixir以下のコマンドを実行して環境変数を設定する
source /home/livebook/setup_for_wsl.shLiveBook を起動する
/app/bin/livebook start二つ、異なるターミナルを開き、それぞれで起動したプロセスが通信できることを確認する
Docker 上で実行している場合は以下のコマンドで docker コンテナ内に入る
docker exec -it livebook /bin/bash一方のターミナル (以後、ターミナル foo とする) で以下のコマンドを実行する
iex --sname foo他方のターミナル (以後、ターミナル bar とする) で以下のコマンドを実行する
iex --sname barターミナル foo で以下のコマンドを実行する
Node.ping(:bar@<ホスト名>):pong が返ってくることを確認する
ターミナル bar で以下のコマンドを実行する
Node.ping(:foo@<ホスト名>):pong が返ってくることを確認する
ターミナル bar で以下のコマンドを実行する
Node.ping(:baz@<ホスト名>):pang が返ってくることを確認する
ターミナル foo で以下のコマンドを実行する
Node.list[] が返ってくることを確認する
ターミナル bar で以下のコマンドを実行する
Node.list[] が返ってくることを確認する
ターミナル foo で以下のコマンドを実行する
Node.connect(:bar@<ホスト名>)true が返ってくることを確認する
ターミナル foo で以下のコマンドを実行する
Node.list[:bar@<ホスト名>] が返ってくることを確認する
ターミナル bar で以下のコマンドを実行する
Node.list[:foo@<ホスト名>] が返ってくることを確認する
ターミナル bar で以下のコマンドを実行する
pid = self()
:global.register_name( :reciever, pid )
receive do message -> IO.puts( "received: #{ message }" ) endターミナル foo で以下のコマンドを実行する
to_pid = :global.whereis_name( :reciever )
send( to_pid, "send from foo" )ターミナル bar で received: send from foo と表示されることを確認する
ターミナル foo で以下のコマンドを実行する
send( to_pid, "second message" )ターミナル bar で以下のコマンドを実行する
receive do message -> IO.puts( "received: #{ message }" ) endターミナル bar で received: second message と表示されることを確認する
サンプル用のリポジトリーをクローンする
cd \
&& git clone https://github.com/RyoWakabayashi/phoenix-liveview-example.git \
&& cd phoenix-liveview-examplemix setupコンテナ外部からアクセスできるように設定ファイルを編集する
sed -i -e 's/127, 0, 0, 1/0, 0, 0, 0/g' config/dev.exsmix phx.server表示される URL にアクセスする
以下のコマンドで新規プロジェクトを作成する
※今回は DB を使わないので --no-ecto を付けている
mix phx.new hello_world --no-ectoプロジェクトが hello_world ディレクトリーに作成される
hello_world ディレクトリーに移動して Phoenix を起動する
cd hello_world
sed -i -e 's/127, 0, 0, 1/0, 0, 0, 0/g' config/dev.exs
mix phx.server