docker-node
docker-node copied to clipboard
environment variable handling (with ":" ) broken in subset of docker images
Steps to reproduce:
1. Initialize a dummy project
➜ node_docker yarn init
yarn init v0.24.5
question name (node_docker):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
success Saved package.json
✨ Done in 7.21s.
2. Docker image node:8.15.1 ### Nothing!!!
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1 sh -c "yarn env | grep foo"
3. Docker image node:8.15.1-alpine ### WORKS!!!
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1-alpine sh -c "yarn env | grep foo"
"foo:bar:baz": "jazz",
4. Docker image node:8.15.1-jessie-slim ### WORKS!!!
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1-jessie-slim sh -c "yarn env | grep foo"
Unable to find image 'node:8.15.1-jessie-slim' locally
8.15.1-jessie-slim: Pulling from library/node
2a639da97f77: Pull complete
a113511e687c: Pull complete
573f6460222d: Pull complete
913f23ff918d: Pull complete
Digest: sha256:f098744a5e5e878cf8953e3078c3d25e75f767c8a83792c79199965d17d1967e
Status: Downloaded newer image for node:8.15.1-jessie-slim
"foo:bar:baz": "jazz",
5. Docker image node:8.15.1-stretch ### Nothing!!!
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1-stretch sh -c "yarn env | grep foo"
6. Docker image node:8.15.1-stretch-slim ### Nothing!!!
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1-stretch-slim sh -c "yarn env | grep foo"
Unable to find image 'node:8.15.1-stretch-slim' locally
8.15.1-stretch-slim: Pulling from library/node
27833a3ba0a5: Pull complete
63859d5abfc2: Pull complete
6f1d42e1c6ba: Pull complete
360a3fb73c58: Pull complete
Digest: sha256:fb7a4f465007a5b91feda51e17af1b551f3cb4d70be22c6dd4ae381165c4382d
Status: Downloaded newer image for node:8.15.1-stretch-slim
I thnk this is more related to the base images and/or how docker environment variables are added by docker. Using export foo:bar:baz=test or export "foo:bar:baz in Ubuntu results in -bash: export: 'foo:bar:baz': not a valid identifier and using sh: sh: export: 'foo:bar:baz=test': not a valid identifier
@LaurentGoderre Agree, but it seems to work in node:8.12.0 why did it break since node:8.13 and forward?
The default base image changed from debian jessie to debian stretch at that version. You can still us newer versions of Node 8 using the tag node:8.13.x-jessie
@LaurentGoderre Agree and confirm that it works! Thanks for helping us on this!
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.12.0 sh -c "yarn env | grep foo"
"foo:bar:baz": "jazz",
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.13-jessie sh -c "yarn env | grep foo"
"foo:bar:baz": "jazz",
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1-jessie sh -c "yarn env | grep foo"
"foo:bar:baz": "jazz",
We tried to update our node base image yesterday after the old debian mirrors stopped working and came across this issue!
If you run yarn env directly (removing sh -c "..."), the environment variables should persist as expected as well. See https://github.com/docker-library/openjdk/issues/135 for a similar discussion about environment variables with periods in them over on the openjdk image (for which the solution was to use bash instead of sh on Debian, since bash is more forgiving about environment variables being passed in than dash is, which is the default sh provider on Debian). Not sure if that'd work for colons, but it's worth a try.
@tianon Nope. doesn't work
Doesn't work with sh
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1 sh -c "yarn env | grep foo"
Unable to find image 'node:8.15.1' locally
8.15.1: Pulling from library/node
e79bb959ec00: Pull complete
d4b7902036fe: Pull complete
1b2a72d4e030: Pull complete
d54db43011fd: Pull complete
69d473365bb3: Pull complete
6e2490ee2dc8: Pull complete
fc66dfb5c5fd: Pull complete
f0614876c4bf: Pull complete
Digest: sha256:918f0be3932f555cd2645ca828b9c231a2dab10d9cf2dbb58896411207bbe52f
Status: Downloaded newer image for node:8.15.1
Doesn't work with yarn env
➜ node_docker docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1 yarn env
yarn run v1.12.3
{
"NODE": "/usr/local/bin/node",
"INIT_CWD": "/opt/ct",
"NODE_VERSION": "8.15.1",
"HOSTNAME": "9e0990dd0df2",
"YARN_VERSION": "1.12.3",
"HOME": "/root",
"TERM": "xterm",
"PATH": "/tmp/yarn--1553720985186-0.7367426959461405:/opt/ct/node_modules/.bin:/usr/local/share/.config/yarn/link/node_modules/.bin:/opt/ct/node_modules/.bin:/usr/local/share/.config/yarn/link/node_modules/.bin:/usr/local/libexec/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/local/bin/node_modules/npm/bin/node-gyp-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PWD": "/opt/ct",
"npm_lifecycle_event": "env",
"npm_node_execpath": "/usr/local/bin/node",
"npm_execpath": "/opt/yarn-v1.12.3/bin/yarn.js",
"npm_config_argv": "{\"remain\":[],\"cooked\":[\"run\",\"env\"],\"original\":[\"env\"]}",
"npm_package_license": "MIT",
"npm_package_main": "index.js",
"npm_package_version": "1.0.0",
"npm_package_name": "node_docker",
"npm_config_version_tag_prefix": "v",
"npm_config_version_git_tag": "true",
"npm_config_version_commit_hooks": "true",
"npm_config_version_git_sign": "",
"npm_config_version_git_message": "v%s",
"npm_config_init_version": "1.0.0",
"npm_config_init_license": "MIT",
"npm_config_save_prefix": "^",
"npm_config_bin_links": "true",
"npm_config_ignore_scripts": "",
"npm_config_ignore_optional": "",
"npm_config_registry": "https://registry.yarnpkg.com",
"npm_config_strict_ssl": "true",
"npm_config_user_agent": "yarn/1.12.3 npm/? node/v8.15.1 linux x64",
"npm_config_version": "1.12.3"
}
Done in 0.16s.
Doesn't work with bash
docker run --rm -it -e foo:bar:baz=jazz -v $PWD:/opt/ct -w /opt/ct node:8.15.1 bash -c "yarn env | grep foo"
Only seems to work is jessie based images
How about
docker run --rm -it -v $PWD:/opt/ct -w /opt/ct node:8.15.1 sh -c "env foo:bar:baz=jazz && yarn env | grep foo"
@LaurentGoderre This goes deeper than this simple example. We use nconf for overriding configurations. we use the default separator : We have this setup across all our nodejs services, its docker-compose files for local development and part of our deployment container task definitions :) We plan to use __ as the separator moving forward.