0

I have a new Google Cloud project where I setup a Docker container to run the app. When I first set it up, I ran into some issues and was able to get the app running after setting an environment variable with export CLOUDSDK_PYTHON=python2 per this issue: https://github.com/docker/compose/issues/5930

But the Shell console restarted or timed out so when I spun up the Shell console again, I was getting the same error. I had to set the environment variable again to run the app, so I was wondering how to automate that or set it for life. When I run export CLOUDSDK_PYTHON=python2 is that only creating the environment variable for the lifetime of the Shell console? Or is it for just the docker container? I'm brand new to docker containers so I'm not sure what else I would need to setup on it.

1 Answer 1

1

If you are using a DockerFile to build the image, you can use the ENV keyword within the DockerFile to set an environment variable,

Usage of the command is as follows:

ENV CLOUDSDK_PYTHON=python2

ENV variables are available during the build and within the image when running on a container. Since the DockerFile describes a set of instructions when creating your image, you will always have this environment variable set when running the image in a container (thus the beauty of Docker to package up everything you need to ensure it runs perfectly every time)

You can also add the environment variable during the 'docker run' command as follows (if you are running an external image):

$ docker run -e "CLOUDSDK_PYTHON=python2" alpine

(information found at the following source - https://vsupalov.com/docker-arg-env-variable-guide/)

Sign up to request clarification or add additional context in comments.

2 Comments

Still getting the same error regardless of where I enter that command ENV CLOUDSDK_PYTHON=python2 in the dockerfile. How do I add that as an argument to a docker-compose command? I usually run the following command to build my app: docker-compose build
Can you please share your dockerfile + docker-compose file? Will help to reproduce the issue locally

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.