Docker image for running pyraf.
To build and push a new image:
$ docker build -t huitacademictechnology/pyraf .
$ docker run --rm -it huitacademictechnology/pyraf:latest /bin/bash -c "pyraf --version"
$ docker login
$ docker push huitacademictechnology/pyraf
To run pyraf
and use X apps, follow the instructions below.
The Linux graphical windowing system is called X11, also known as X Windows, or X for short. X forwarding is a feature of X where a graphical program runs on one computer, but the user interacts with it on another computer. If you've ever used Remote Desktop, it's conceptually like that, but it works on a program-by-program or window-by-window basis.
For Mac OS X, install XQuartz.
- Ensure that you have an
~/.Xauthority
file (a binary file used to authorize connections to theDISPLAY
):$ touch ~/.Xauthority
- Add
XAuthLocation
to~/.ssh/config
:This is so thatXAuthLocation /opt/X11/bin/xauth
ssh
knows where to find thexauth
program that is provided by XQuartz, since it's in a non-standard location. - Add
ForwardX11Timeout
to~/.ssh/config
:This increases the default timeout from 20min to 10hrs. Note that this only applies ifForwardX11Timeout 10h
ForwardX11Trusted no
(e.g.ssh -X
instead ofssh -Y
).
The most important environment variable for X is $DISPLAY
. This will be set by your X server (e.g. XQuartz) and defines a value in the following format: hostname:D.S
.
hostname
is the name of the computer the X server runs on (localhost
if omitted).D
is a sequence number if there are multiple displays.S
is a screen number (typically 0 because there's one secreen)
The .Xauthority
file is used to authorize cookie-based access to the $DISPLAY
. It defines a "magic cookie" that must be presented by X clients when connecting to the X display server.
Since this is a binary file, you can't view it directly, but must use the xauth
command:
$ echo $DISPLAY
$ xauth list
See also:
Assumes you have Docker Desktop for Mac and you want to run the docker image locally.
- Install socat:
$ brew install socat
- Launch XQuartz
$ open -a XQuartz
- Go to the XQuartz security tab and ensure Allow connections from network clients is checked.
- Use
socat
to forward traffic from port 6000 to the unix display socket:$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" $ lsof -i TCP:6000 # verify socat is listening
- Start docker:
$ docker pull huitacademictechnology/pyraf:latest $ docker run --rm -e DISPLAY=docker.for.mac.host.internal:0 -it huitacademictechnology/pyraf:latest /bin/tcsh
- Run an X11 app such as
xterm
orxeyes
If successful, you should see an$ xterm &
xterm
open on your desktop. - Run
pyraf
:$ pyraf
Assumes you have an Ubuntu EC2 instance with Docker Engine installed and you want to run the docker image remotely, but interact with it locally on your desktop.
- Launch XQuartz
$ open -a XQuartz
- Connect to the EC2 with X Forwarding enabled:
$ ssh -X ubuntu@<IP> $ touch ~/.Xauthority
- Start docker:
$ docker pull huitacademictechnology/pyraf:latest $ docker run --rm -e DISPLAY --network host -v "$HOME/.Xauthority:/root/.Xauthority:rw" -it huitacademictechnology/pyraf:latest /bin/tcsh
- Run an X11 app such as
xterm
orxeyes
If successful, you should see an$ xterm &
xterm
open on your desktop. - Run
pyraf
:$ pyraf
Note: The X client within the docker container must be able to find the X server specified in the $DISPLAY
. By setting the docker network to host
instead of bridge
, it will be able to easily resolve the hostname and connect to the X server (which in this case is SSHD proxying the request back to your computer). Note that this technique is not recommended for deployment, just for testing.