To create a Docker container for a graphical application, you need three components in your Dockerfile:
- Instructions to install the application and its dependencies.
- A script to start the application, stored at
/startapp.sh in the container. - The name of the application set via the
APP_NAME environment variable.
Follow these steps to build and run an example container (e.g., xterm):
- Create a
startapp.sh script with exec <path_to_binary>. - Make the script executable:
chmod +x startapp.sh. - Create a
Dockerfile using the baseimage, installing dependencies, copying the script, and setting APP_NAME. - Build the image:
docker build -t <tag> .. - Run the container, mapping ports
5800 (Web GUI) and 5900 (VNC).
### Dockerfile
```dockerfile
# Pull the baseimage.
FROM jlesage/baseimage-gui:alpine-3.19-v4
# Install xterm.
RUN add-pkg xterm
# Copy the start script.
COPY startapp.sh /startapp.sh
# Set the application name.
RUN set-cont-env APP_NAME "Xterm"
startapp.sh
#!/
exec /usr/bin/xterm
Build and Run
chmod +x startapp.sh
docker build -t docker-xterm .
docker run --rm -p 5800:5800 -p 5900:5900 docker-xterm