jlesage / docker-baseimage-gui

A minimal docker baseimage to ease creation of X graphical application containers
MIT License
1.2k stars 179 forks source link

Ubuntu release peculiarities. #122

Closed salamander2 closed 9 months ago

salamander2 commented 9 months ago

Thank you for docker-baseimage-gui "(I have a couple of support questions)"

My image version is Ubuntu-20-04

Setting environment variables

Problems:

  1. there is no /etc/cont-env.d/ directory in this version
  2. The following instruction does not work RUN set-cont-env APP_NAME "Xterm" because set-conv-env does not exist in this version.
  3. I CAN set enviromnent variables using the ENV command, except for the HOME variable. I have no idea why this one does not work.
> cat Dockerfile 

# Pull base image.
FROM jlesage/baseimage-gui:ubuntu-20.04

# Copy the minimized, premade JRE (here it's Java 11)
COPY jre_11 /opt/java/

WORKDIR /app
RUN echo 'alias ll="ls -l"' >> ~/.bashrc

ARG DOMAIN=ca/quarkphysics/harwood/

# Copy only the class files to /app
COPY src/$DOMAIN/sciOlympics /app/$DOMAIN/sciOlympics

# Set environment variables
ENV HOME="/app"
ENV APP_NAME="SciOlympics Function ID"
ENV APP_CMD="/opt/java/bin/java ca.quarkphysics.harwood.sciOlympics.Function"

# Copy the start script.
COPY startapp.sh /startapp.sh

# Usage: 
#docker build -t sci_olympics .
#docker run --rm --restart=unless-stopped -p 5800:5800 -p 5900:5900 sci_olympics

And here's my startapp.sh (which is setup so that it never needs to be modified again)

#!/bin/sh

echo "***"
echo $HOME
echo "+++"
echo $APP_CMD
echo "xxx"
echo $APP_NAME
echo "***"

cd $HOME
exec $APP_CMD

And here is the output from the docker run.
Note that all the variables print, EXCEPT for $HOME, which means that the program does not run. (Why doesn't "WORKDIR" work?)

logmonitor] no file to monitor: disabling service...
[app] starting SciOlympics Function ID...
***

+++
/opt/java/bin/java ca.quarkphysics.harwood.sciOlympics.Function
xxx
SciOlympics Function ID
***
/startapp.sh: 15: cd: can't cd to

[services.d] done.
Error: Could not find or load main class ca.quarkphysics.harwood.sciOlympics.Function
jlesage commented 9 months ago

You are not using the correct image tag. You probably want to use ubuntu-20.04-v4.

So your Dockerfile should have:

FROM jlesage/baseimage-gui:ubuntu-20.04-v4
salamander2 commented 9 months ago

Yep. That did it!

I did find out one other peculiarity which might need fixing.

Dockerfile:

COPY startapp.sh /startapp.sh
RUN chmod 755 /startapp.sh

Yes. I have to add "chmod 755" otherwise it does not work, EVEN THOUGH /etc/cont-init.d/00-app-script.sh claims to set the permissions to 755. I've tested it setting my host file permissions to 644.

Here's the content of /etc/cont-init.d/00-app-script.sh (which doesn't seem to work as intended):

#!/usr/bin/with-contenv sh

#
# Make sure the startapp.sh has execution permission.
#

set -e # Exit immediately if a command exits with a non-zero status.
set -u # Treat unset variables as an error.

if [ -e /startapp.sh ] ; then
    chmod 755 /startapp.sh
    sync
fi

# vim:ft=sh:ts=4:sw=4:et:sts=4

Anyway, this is now a moot point because you can just put "startapp.sh" permanently in your baseimage-gui and set the permissions as well before you create your image. Users will never have to modify/copy it again.

jlesage commented 9 months ago

Humm /etc/cont-init.d/00-app-script.sh is not part of the baseimage...

In your source tree, startapp.sh should already have execute permission.

salamander2 commented 9 months ago

Humm /etc/cont-init.d/00-app-script.sh is not part of the baseimage...

Strange. I didn't add it.

Anyway, I think the best thing to do is to add this to the Dockerfile and it will prevent any potential problems.

RUN chmod 755 /startapp.sh