Is it possible to source an environment file when launching a docker-compose file from Docker Stack The Next CEO of Stack OverflowCopying files from Docker container to hostCopying files from host to Docker containerDocker-compose volumes doesn't copy any filesAdding files to standard images using docker-composeHow to persist data in a dockerized postgres database using volumesdocker-compose copies files as folderVolume share from container to host docker-composeUnable to access DOCKER ContainerDocker socket crash after stack updocker-compose as a production environment without internet
Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?
The past simple of "gaslight" – "gaslighted" or "gaslit"?
Why isn't acceleration always zero whenever velocity is zero, such as the moment a ball bounces off a wall?
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Should I tutor a student who I know has cheated on their homework?
Is the D&D universe the same as the Forgotten Realms universe?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Why isn't the Mueller report being released completely and unredacted?
How do I align (1) and (2)?
Solving system of ODEs with extra parameter
Is micro rebar a better way to reinforce concrete than rebar?
Why didn't Khan get resurrected in the Genesis Explosion?
Is there a way to save my career from absolute disaster?
Which one is the true statement?
What happened in Rome, when the western empire "fell"?
Is it possible to use a NPN BJT as switch, from single power source?
Domestic-to-international connection at Orlando (MCO)
I want to delete every two lines after 3rd lines in file contain very large number of lines :
How many extra stops do monopods offer for tele photographs?
Can we say or write : "No, it'sn't"?
Won the lottery - how do I keep the money?
Legal workarounds for testamentary trust perceived as unfair
Is wanting to ask what to write an indication that you need to change your story?
Rotate a column
Is it possible to source an environment file when launching a docker-compose file from Docker Stack
The Next CEO of Stack OverflowCopying files from Docker container to hostCopying files from host to Docker containerDocker-compose volumes doesn't copy any filesAdding files to standard images using docker-composeHow to persist data in a dockerized postgres database using volumesdocker-compose copies files as folderVolume share from container to host docker-composeUnable to access DOCKER ContainerDocker socket crash after stack updocker-compose as a production environment without internet
I'd like to do create a sym link and source an environment file from my docker-compose file when I launch using Docker Stack. Like this:
version: '3'
services:
hello_world:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./config:/config:ro
- ./data:/data
command:
- /bin/bash
- -c
- |
ln -s /config/lala /etc/nginx/lala
source /config/env
nginx -g 'daemon off;'
You can see that my command first creates a symbolic link, then sources an environment file found within the /config directory that is volume mounted, then launches nginx. I know that there are other ways to put environment variables in the docker-compose file, but I'm trying to decouple environment aspects from the docker-compose file itself.
I'm launching this using Docker Stack, like this:
docker stack deploy -c docker-compose-local.yml nginx-test
but when I shell into the container with:
docker exec -it 5c /bin/bash
I can see that while my symbolic link worked my environment variables are not loaded:
root@5c562e102cf4:/# env
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
root@5c562e102cf4:/# cat /etc/nginx/lala
asdfadf
root@5c562e102cf4:/# source /config/env
root@5c562e102cf4:/# env
TEST_NGINX_ENV_SETTING=test_setting1
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
TEST_POSTGRES_ENV_SETTING=test_setting2
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
Really appreciate anyone who can help me source this file from the mounted volume OR understand why what I'm trying to do may never work at all.
linux docker docker-compose environment-variables docker-stack
add a comment |
I'd like to do create a sym link and source an environment file from my docker-compose file when I launch using Docker Stack. Like this:
version: '3'
services:
hello_world:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./config:/config:ro
- ./data:/data
command:
- /bin/bash
- -c
- |
ln -s /config/lala /etc/nginx/lala
source /config/env
nginx -g 'daemon off;'
You can see that my command first creates a symbolic link, then sources an environment file found within the /config directory that is volume mounted, then launches nginx. I know that there are other ways to put environment variables in the docker-compose file, but I'm trying to decouple environment aspects from the docker-compose file itself.
I'm launching this using Docker Stack, like this:
docker stack deploy -c docker-compose-local.yml nginx-test
but when I shell into the container with:
docker exec -it 5c /bin/bash
I can see that while my symbolic link worked my environment variables are not loaded:
root@5c562e102cf4:/# env
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
root@5c562e102cf4:/# cat /etc/nginx/lala
asdfadf
root@5c562e102cf4:/# source /config/env
root@5c562e102cf4:/# env
TEST_NGINX_ENV_SETTING=test_setting1
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
TEST_POSTGRES_ENV_SETTING=test_setting2
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
Really appreciate anyone who can help me source this file from the mounted volume OR understand why what I'm trying to do may never work at all.
linux docker docker-compose environment-variables docker-stack
Does it work with normal docker-compose command ? I tested similar scenario with nodejs image with docker-compose command and it worked.
– Mostafa Hussein
Mar 8 at 0:36
It might, Mostafa, but it doesn't matter because I'm in a world where I have to use docker stack.
– Bill Noto
Mar 8 at 2:37
I could suggest adding your env file into a volume and then run your commands as an entrypoint.
– Rodrigo Loza
Mar 8 at 3:31
add a comment |
I'd like to do create a sym link and source an environment file from my docker-compose file when I launch using Docker Stack. Like this:
version: '3'
services:
hello_world:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./config:/config:ro
- ./data:/data
command:
- /bin/bash
- -c
- |
ln -s /config/lala /etc/nginx/lala
source /config/env
nginx -g 'daemon off;'
You can see that my command first creates a symbolic link, then sources an environment file found within the /config directory that is volume mounted, then launches nginx. I know that there are other ways to put environment variables in the docker-compose file, but I'm trying to decouple environment aspects from the docker-compose file itself.
I'm launching this using Docker Stack, like this:
docker stack deploy -c docker-compose-local.yml nginx-test
but when I shell into the container with:
docker exec -it 5c /bin/bash
I can see that while my symbolic link worked my environment variables are not loaded:
root@5c562e102cf4:/# env
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
root@5c562e102cf4:/# cat /etc/nginx/lala
asdfadf
root@5c562e102cf4:/# source /config/env
root@5c562e102cf4:/# env
TEST_NGINX_ENV_SETTING=test_setting1
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
TEST_POSTGRES_ENV_SETTING=test_setting2
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
Really appreciate anyone who can help me source this file from the mounted volume OR understand why what I'm trying to do may never work at all.
linux docker docker-compose environment-variables docker-stack
I'd like to do create a sym link and source an environment file from my docker-compose file when I launch using Docker Stack. Like this:
version: '3'
services:
hello_world:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./config:/config:ro
- ./data:/data
command:
- /bin/bash
- -c
- |
ln -s /config/lala /etc/nginx/lala
source /config/env
nginx -g 'daemon off;'
You can see that my command first creates a symbolic link, then sources an environment file found within the /config directory that is volume mounted, then launches nginx. I know that there are other ways to put environment variables in the docker-compose file, but I'm trying to decouple environment aspects from the docker-compose file itself.
I'm launching this using Docker Stack, like this:
docker stack deploy -c docker-compose-local.yml nginx-test
but when I shell into the container with:
docker exec -it 5c /bin/bash
I can see that while my symbolic link worked my environment variables are not loaded:
root@5c562e102cf4:/# env
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
root@5c562e102cf4:/# cat /etc/nginx/lala
asdfadf
root@5c562e102cf4:/# source /config/env
root@5c562e102cf4:/# env
TEST_NGINX_ENV_SETTING=test_setting1
HOSTNAME=5c562e102cf4
NJS_VERSION=1.15.9.0.2.8-1~stretch
TEST_POSTGRES_ENV_SETTING=test_setting2
NGINX_VERSION=1.15.9-1~stretch
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
Really appreciate anyone who can help me source this file from the mounted volume OR understand why what I'm trying to do may never work at all.
linux docker docker-compose environment-variables docker-stack
linux docker docker-compose environment-variables docker-stack
asked Mar 7 at 16:49
Bill NotoBill Noto
391311
391311
Does it work with normal docker-compose command ? I tested similar scenario with nodejs image with docker-compose command and it worked.
– Mostafa Hussein
Mar 8 at 0:36
It might, Mostafa, but it doesn't matter because I'm in a world where I have to use docker stack.
– Bill Noto
Mar 8 at 2:37
I could suggest adding your env file into a volume and then run your commands as an entrypoint.
– Rodrigo Loza
Mar 8 at 3:31
add a comment |
Does it work with normal docker-compose command ? I tested similar scenario with nodejs image with docker-compose command and it worked.
– Mostafa Hussein
Mar 8 at 0:36
It might, Mostafa, but it doesn't matter because I'm in a world where I have to use docker stack.
– Bill Noto
Mar 8 at 2:37
I could suggest adding your env file into a volume and then run your commands as an entrypoint.
– Rodrigo Loza
Mar 8 at 3:31
Does it work with normal docker-compose command ? I tested similar scenario with nodejs image with docker-compose command and it worked.
– Mostafa Hussein
Mar 8 at 0:36
Does it work with normal docker-compose command ? I tested similar scenario with nodejs image with docker-compose command and it worked.
– Mostafa Hussein
Mar 8 at 0:36
It might, Mostafa, but it doesn't matter because I'm in a world where I have to use docker stack.
– Bill Noto
Mar 8 at 2:37
It might, Mostafa, but it doesn't matter because I'm in a world where I have to use docker stack.
– Bill Noto
Mar 8 at 2:37
I could suggest adding your env file into a volume and then run your commands as an entrypoint.
– Rodrigo Loza
Mar 8 at 3:31
I could suggest adding your env file into a volume and then run your commands as an entrypoint.
– Rodrigo Loza
Mar 8 at 3:31
add a comment |
1 Answer
1
active
oldest
votes
Maybe you could try copying the content of your volume in a modified dockerfile and load the environment variables through an entrypoint.
The dockerfile would be:
FROM nginx:latest
COPY ./config /config
ENTRYPOINT ["bash", "start.sh"]
start.sh would be:
# !/bin/bash
source /config/env
nginx -g 'daemon off;'
And the stack.yml file would be:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./data:/data
Note: you could also add your symbolic link in the entrypoint.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048976%2fis-it-possible-to-source-an-environment-file-when-launching-a-docker-compose-fil%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Maybe you could try copying the content of your volume in a modified dockerfile and load the environment variables through an entrypoint.
The dockerfile would be:
FROM nginx:latest
COPY ./config /config
ENTRYPOINT ["bash", "start.sh"]
start.sh would be:
# !/bin/bash
source /config/env
nginx -g 'daemon off;'
And the stack.yml file would be:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./data:/data
Note: you could also add your symbolic link in the entrypoint.
add a comment |
Maybe you could try copying the content of your volume in a modified dockerfile and load the environment variables through an entrypoint.
The dockerfile would be:
FROM nginx:latest
COPY ./config /config
ENTRYPOINT ["bash", "start.sh"]
start.sh would be:
# !/bin/bash
source /config/env
nginx -g 'daemon off;'
And the stack.yml file would be:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./data:/data
Note: you could also add your symbolic link in the entrypoint.
add a comment |
Maybe you could try copying the content of your volume in a modified dockerfile and load the environment variables through an entrypoint.
The dockerfile would be:
FROM nginx:latest
COPY ./config /config
ENTRYPOINT ["bash", "start.sh"]
start.sh would be:
# !/bin/bash
source /config/env
nginx -g 'daemon off;'
And the stack.yml file would be:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./data:/data
Note: you could also add your symbolic link in the entrypoint.
Maybe you could try copying the content of your volume in a modified dockerfile and load the environment variables through an entrypoint.
The dockerfile would be:
FROM nginx:latest
COPY ./config /config
ENTRYPOINT ["bash", "start.sh"]
start.sh would be:
# !/bin/bash
source /config/env
nginx -g 'daemon off;'
And the stack.yml file would be:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./data:/data
Note: you could also add your symbolic link in the entrypoint.
answered Mar 8 at 3:40
Rodrigo LozaRodrigo Loza
686
686
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55048976%2fis-it-possible-to-source-an-environment-file-when-launching-a-docker-compose-fil%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does it work with normal docker-compose command ? I tested similar scenario with nodejs image with docker-compose command and it worked.
– Mostafa Hussein
Mar 8 at 0:36
It might, Mostafa, but it doesn't matter because I'm in a world where I have to use docker stack.
– Bill Noto
Mar 8 at 2:37
I could suggest adding your env file into a volume and then run your commands as an entrypoint.
– Rodrigo Loza
Mar 8 at 3:31