Skip to content

Instantly share code, notes, and snippets.

@Griefed
Created April 2, 2021 13:19
Show Gist options
  • Save Griefed/9f400f00cd264cbe7b6c676a2dcf1a12 to your computer and use it in GitHub Desktop.
Save Griefed/9f400f00cd264cbe7b6c676a2dcf1a12 to your computer and use it in GitHub Desktop.
Why does -cgen work but -cont does not?

Hello everyone I am trying to set up a container for my Java application using lsiobase/alpine:3.12 and openjdk8-jre. Said application supports two arguments, -cgen and -cont. -cont is supposed to be used when the application is run in a docker environment. The service is started via the run script:

#!/usr/bin/with-contenv bash

cd /app/serverpackcreator

exec s6-setuidgid abc java -jar /app/serverpackcreator/serverpackcreator.jar -$START

Where START is set in the docker-compose as START=cont I've tested whether that is passed correctly by setting START to cgen and the application starts into the corresponding mode, however, when it is set to cont it doesn't start to the corresponding mode. When I run serverpackcreator.jar -cont in my Windows CLI or a Linux CLI in a VM or on my VPS, it works fine, but as soon as I try to run it with the s6 overlay in a container, the argument is...ignored?

I've tried changing the argument to different ones, for example -docker and -dock but no dice. I'm slowly starting to pull out my hair here, so I was hoping anyone would have an idea as to what I am doing wrong here. Is there something I need to keep in mind when using s6 and command line arguments which I am missing?

The check for the argument in my Java application is this:

        if (Arrays.asList(args).contains(Reference.CONFIG_GEN_ARGUMENT) || (!Reference.oldConfigFile.exists() && !Reference.configFile.exists())){
            CLISetup.setup();
        } else if (Arrays.asList(args).contains(Reference.DOCKER_ENV_ARGUMENT)) {
            appLogger.info(String.format("You started ServerPackCreator with the \"%s\" argument. Adding prefix \"/data/\" to modpackDir...", Reference.DOCKER_ENV_ARGUMENT));
            Reference.dockerEnv = true;
        } else { Reference.dockerEnv = false; }

and as I said, it works fine for -cgen, but not for -cont, -dock or -docker, in the container. Locally, non-docker, it all works as expected...

@andrewdsmith
Copy link

It might help to see your Dockerfile and docker-compose.yml.

@andrewdsmith
Copy link

@andrewdsmith
Copy link

Okay, having looked at this, first thing I would do is log the contents of args in your app in a way you can see when you run the container. Then you'll know if it's the way you're invoking the app (unlikely given what you've said) or the app logic quoted here. You could also try adding an env or env | sort line to the run script, so that you see if the script has the env var you're expecting (i.e. is it getting passed in from docker-compose as you're expecting).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment