Hildy
Hildy

Reputation: 510

Run a Docker Container from a Desktop File Without Terminal GUI?

I have a couple of Docker images I've built for this and that;one for scanner program, another for a browser etc. Once I had them working, I created .desktop files that execute a bash run scripts I've created to run a container with them.

My question is: is there a way to run the .desktop file without the terminal GUI showing up? I've tried a couple of approaches with no success.

For instance, I've tried:

[Desktop Entry]
Name=gscan2pdf
Icon=gscan2pdf.png
Exec=gnome-terminal -e 
"/home/hildy/Documents/repos/docker/gscan2pdf/run_gscan.sh"
Type=Application
Terminal=false

As well as:

[Desktop Entry]
Name=gscan2pdf
Icon=gscan2pdf.png
Exec="/home/hildy/Documents/repos/docker/gscan2pdf/run_gscan.sh"
Type=Application
Terminal=true

Both of these execute the scripts just fine of course, I'd just like it better if the application launched without a terminal GUI launching first. Host System: CentOS 7 - Gnome 3 Desktop

One example of a run script:

#!/bin/bash

HOST_UID=$(id -u)
HOST_GID=$(id -g)

XSOCK=/tmp/.X11-unix && 
XAUTH=/tmp/.docker.xauth &&

touch $XAUTH &&
xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - &&

#These are only run the first time a container is run from the image
#docker run -e NEW_USER="${USER}" -e NEW_UID="${HOST_UID}" -e 
#NEW_GID="${HOST_GID}" hildy/gscan2pdf:v1 
#LAST_CONTAINER=$(docker ps -lq) &&
#docker commit "${LAST_CONTAINER}" hildy/gscan2pdf:v1

docker run \
-ti \
--user $USER \
--privileged \
-v /dev/bus/usb:/dev/bus/usb \
-v $XAUTH:$XAUTH -v $XSOCK:$XSOCK -v /home/$USER:/home/$USER \
-e XAUTHORITY=$XAUTH -e DISPLAY \
--entrypoint "" hildy/gscan2pdf:v1 gscan2pdf &>/dev/null

Upvotes: 1

Views: 2701

Answers (1)

Hildy
Hildy

Reputation: 510

I have found an answer to my question. The issue was that the command to run the container contained the -i option for an interactive terminal. @sneep was correct in the comments to the question when he said "It should work with Terminal=false." His technique to add a line to the script to create a log file is also a great technique, which I will certainly use in the future and it helped me to diagnose the issue.

I can also confirm that replacing -it with -d for detached mode, as suggested by @Oleg Skylar, works.

Amended Docker command for the run script:

docker run \
-t \
--user $USER \
--privileged \
-v /dev/bus/usb:/dev/bus/usb \
-v $XAUTH:$XAUTH -v $XSOCK:$XSOCK -v /home/$USER:/home/$USER \
-e XAUTHORITY=$XAUTH -e DISPLAY \
--entrypoint "" hildy/gscan2pdf:v1 gscan2pdf &>/dev/null

Amended .desktop file:

[Desktop Entry]
Name=gscan2pdf
Icon=gscan2pdf.png
Exec=/home/hildy/Documents/repos/docker/gscan2pdf/run_gscan.sh
Type=Application
Terminal=false
StartupNotify=true

Upvotes: 2

Related Questions