Skip to content

How to Use Environment Variables in Deployments

By default, TurboCloud uses Docker containers to deploy applications, services, and websites. You can use environment variables in the same way as you would with standard Docker setups.

Environment Variables in Dockerfile

To add environment variables to a Dockerfile, use the ENV <key>=<value> [<key>=<value>...] syntax (check the official Docker documentation for more information):

FROM node:18
ENV MY_NAME="John Doe"
ENV MY_DOG=Rex\ The\ Dog
ENV MY_CAT="Fluffy"

After setting environment variables in your Dockerfile, you can access them within your application using standard libraries for environment variable management. Remember, these variables are only available inside the container.

This method is flexible and vendor-independent because you can deploy the Dockerfile almost anywhere. Even if you decide not to use TurboCloud in the future, all environment variables will still be stored in your Git repository.

Environment Variables with docker run

If you prefer not to manage environment variables via the Dockerfile, you can pass them when starting a container (i.e., using docker run). In TurboCloud, you can set these variables from the New Environment or Edit Environment screen: TurboCloud Web Console → Services → Select Service → New (or Edit) Environment.

Questions?

Feel free to contact us at hey@turbocloud.dev.