Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Last active October 10, 2023 15:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasjhenry/10c4c5a43501e1f77cfd589ce089c864 to your computer and use it in GitHub Desktop.
Save nicholasjhenry/10c4c5a43501e1f77cfd589ce089c864 to your computer and use it in GitHub Desktop.
Observer Elixir/BEAM inside a running Docker container using SSH

Add ports to docker-compose.yml:

    - "4369:4369"
    - "9001:9001"
    - "2022:22"

Add this to Dockerfile:

RUN apk --update add --no-cache openssh bash \
  && sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
  && echo "root:root" | chpasswd \
  && rm -rf /var/cache/apk/*
RUN sed -ie 's/#Port 22/Port 22/g' /etc/ssh/sshd_config
RUN sed -ri 's/#HostKey \/etc\/ssh\/ssh_host_key/HostKey \/etc\/ssh\/ssh_host_key/g' /etc/ssh/sshd_config
RUN sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_rsa_key/HostKey \/etc\/ssh\/ssh_host_rsa_key/g' /etc/ssh/sshd_config
RUN sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_dsa_key/HostKey \/etc\/ssh\/ssh_host_dsa_key/g' /etc/ssh/sshd_config
RUN sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_ecdsa_key/HostKey \/etc\/ssh\/ssh_host_ecdsa_key/g' /etc/ssh/sshd_config
RUN sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_ed25519_key/HostKey \/etc\/ssh\/ssh_host_ed25519_key/g' /etc/ssh/sshd_config
RUN sed -ie 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
RUN /usr/bin/ssh-keygen -A
RUN ssh-keygen -t rsa -b 4096 -f  /etc/ssh/ssh_host_key

Need to run this in Dockerfile:

/usr/sbin/sshd -D

Run the application:

docker-compose exec application iex --name vm@127.0.0.1 --cookie secret  --erl '-kernel inet_dist_listen_min 9001 inet_dist_listen_max 9001' -S mix phx.server

Map ports:

ssh -p2022 -L 4369:localhost:4369 -L 9001:localhost:9001 root@localhost

Run iex

iex --name console@127.0.0.1 --cookie secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment