Background
I'm testing code in a running docker container. PM2 passes variables in the process level to my app. While my app runs correctly and DOES have access to the environment variables I set in the json file pm2 reads, the new bash session I create to test it with docker exec -it bash DOES NOT have access to those variables. From what I've learned through experimentation and research, docker does not allow modifications to environment variables in a running container. So if I run printenv in my new bash session my variables are not there.
The tests I run with npm test (in a new bash session) are set up to run against a running server (my app that is deployed in the currently running container).
Question
How can I get the same environment variables that my running app on the process level to be available in the environment level so a new bash session can reliably test my app?
I'm relatively new to docker and it's possible that testing on a running container in this way is an anti-pattern. I'm open to suggestions on another way to try this, but I'd prefer to do this "the docker way".
Thanks!
Resources I've Looked At
- The docs show how to manually set environment variables when running
docker exec. I have enough variables to make this cumbersome and it's prone to human error. - This SO post is eerily similar but it assumes that no container is already running. I have an already running container that I'm looking to test.
- This article explains some of the differences between
docker execanddocker run
Aucun commentaire:
Enregistrer un commentaire