N.Ayaz
N.Ayaz

Reputation: 355

Use enviroment variables in docker-compose.yml file in VueJS application

Please tell me how you can pass environment variables to the VUE application from the docker-compose.yml file. For some reason, after the yarn build command in .gitlab-ci.yml, the application sees only env variables that are written in the "env.production" file

My docker-compose.yml

version: "3.7"
services:
  develop_dashboard_frontend:
  image: some_image:latest           
  container_name: develop_dashboard_frontend
  environment:
    VUE_APP_API_URL: "some_api_URL"
  ports:
    - "127.0.0.1:8016:80"
  restart: always

Any ideas?

Upvotes: 0

Views: 450

Answers (1)

Dániel Nagy
Dániel Nagy

Reputation: 21

You will need to put dashes (-) before each environment variable you want to specify, like you did it with ports in your example. Refer to: https://docs.docker.com/compose/environment-variables/

$ cat docker-compose.yml
version: '3'
services:
  api:
    image: 'some_image:tag'
    environment:
     - VARIABLE_NAME=variable_value

You also need to distinguish between build time and runtime environment variables. You can supply environment variables for your build, but that might not be saved for the runtime. It really depends on your build (I'm not familiar with yarn build). However, I recommend using supplying the env variables for run time.

Just define them in the yaml as you tried.

Using $ docker stack deploy or docker-compose up it should work.

Upvotes: 2

Related Questions