Assume a simple Dockerfile
FROM php-fpm:8
ADD entrypoint.sh .
RUN chmod +x entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
CMD ["php-fpm"]
In the entry-point script I just export a variable and print the environment
#!/bin/bash
set -e
export FOO=bar
env // just print the environment while entrypoint is running
Then I build the image as myimage
and use it to deploy a stack in docker swarm mode
docker stack deploy -c docker-compose.yml teststack
// The docker-compose.yml file used is the following:
app:
image: myimage:latest
environment:
APP_ENV: production
Now the question: If a check the logs of the app
service I can see (because of the env
command in the entrypoint) that the FOO variable is exported
docker service logs teststack_app
teststack_app.1.nbcqgnspn1te@xxx | PWD=/var/www/html
teststack_app.1.nbcqgnspn1te@xxx | FOO=bar
teststack_app.1.nbcqgnspn1te@xxx | HOME=/root
However if I login in the running container and manually run env
the FOO variable is not shown
docker container exec -it teststack_app.1.nbcqgnspn1tebirfatqiogmwp bash
root@df9c6d9c5f98:/var/www/html# env // run env inside the container
PWD=/var/www/html
HOME=/root
// No FOO variable :(
What I am missing here?