Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env attribute does not work when a "-" is present #718

Open
scottpecnik opened this issue Sep 7, 2017 · 4 comments
Open

env attribute does not work when a "-" is present #718

scottpecnik opened this issue Sep 7, 2017 · 4 comments

Comments

@scottpecnik
Copy link

scottpecnik commented Sep 7, 2017

I am trying to start an elasticsearch container using the below piece of code. The issue I am having is with setting a JVM environment variable on the env attribute.

docker::run { 'analytics':
    image            => "elasticsearch:${version}",
    command          => 'elasticsearch',
    ports            => ["${port}:9200"],
    env              => ["ES_JAVA_OPTS=\"-Xms4g -Xmx4g\""],
    extra_parameters => [ '--restart=unless-stopped' ],
    require          => Docker::Image['elasticsearch'],
  }

The above code yields the following result:

docker: unknown shorthand flag: 'X' in -Xmx1g"

docker::run { 'analytics':
    image            => "elasticsearch:${version}",
    command          => 'elasticsearch',
    ports            => ["${port}:9200"],
    env              => ["ES_JAVA_OPTS=\"-Xms1g\""],
    extra_parameters => [ '--restart=unless-stopped' ],
    require          => Docker::Image['elasticsearch'],
  }

As a test, if I pass in only a JVM param for the initial heap space (above), I get the following:

docker: Error: Could not find or load main class "-Xms1g"

Seems maybe there is an issue with how the value of env is transformed? However puppet logs show the below, which looks OK...

/usr/bin/docker run --net bridge -m 0b -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -p 9201:9200 --restart=unless-stopped --name analytics elasticsearch:5.4 elasticsearch

At this point i'm not really sure how to proceed and thinking maybe this is a bug?

@Justin-DynamicD
Copy link

So the way the error is reporting it seems docker itself is mistaking the "-" as a docker flag, not as part of the environment variable.

As I don't see any parameters in your string, maybe simplify it with single quotes just to be sure it's not passing something odd? so:

docker::run { 'analytics':
  image => "elasticsearch:${version}",
  command => 'elasticsearch',
  ports => ["${port}:9200"],
  env => ['ES_JAVA_OPTS="-Xms4g -Xmx4g"'],
  extra_parameters => [ '--restart=unless-stopped' ], require => Docker::Image['elasticsearch'],
}

Otherwise I agree: what you're passing should work.

@scottpecnik
Copy link
Author

Thanks for the quick response. I have tried single quotes but get the same result. I agree it seems like docker is interpreting the value incorrectly, but when I run the command that puppet is sending to stdout directly it works. That command again is:

/usr/bin/docker run --net bridge -m 0b -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -p 9201:9200 --restart=unless-stopped --name analytics elasticsearch:5.4 elasticsearch

I wonder if what puppet is printing to stdout is actually different to what it is running?

@abhaynpai
Copy link

Any updates on this issue ? Even I am facing the same problem.

@redstonemercury
Copy link

I just had this same issue and have tried all sorts of escaping of the options (single quotes, double quotes, escaped double quotes, etc.). I'm not sure if this issue is actually tied to this puppet module though, or rather tied to systemd trying to run docker with the flags, since if you grab what's being put in the systemd file and run it manually, it works. For now, I've gone with overriding the entire jvm.options file in docker instead of passing the environment variable, but it's not ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants