[Vuejs]-How to use system environment variables from build in vue?

0👍

With docker you can add variables in docker-compose.yml

   environment:
                MYSQL_ROOT_PASSWORD: 'password'
                MYSQL_DATABASE: 'DB_DATABASE'
                MYSQL_USER: 'DB_USERNAME'
                MYSQL_PASSWORD: 'DB_PASSWORD'
                MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'

0👍

As long as you make the env variables available in node, the node command that serves/build the Vue app will make the variables accessible on process.env.YOUR_VAR in any js file of the Vue project.

So now the question is, how to make docker vars available in node, and the answer is here:
https://medium.com/@felipedutratine/pass-environment-variables-from-docker-to-my-nodejs-or-golang-app-a1f2ddec31f5

Basically it summarizes to: sudo docker run [...] --env-file ./my_env.list [...]

If you need more info on how to create env vars in docker: https://docs.docker.com/compose/environment-variables/

Leave a comment