This is my second post about this particular issue. I've since deleted that question because I've found a better way to explain what exactly I'd like to do.
Essentially, I'd like to pass command line arguments to docker-compose up
and set them as environment variables in my Vue.js web application. The goal is to be able to change the environment variables without rebuilding the container every time.
I'm running into several issues with this. Here are my docker files:
Dockerfile for Vue.js application.
FROM node:latest as build-stage
WORKDIR /app
# Environment variable.
ENV VUE_APP_FOO=FOO
COPY package*.json ./
RUN npm install
COPY ./ .
RUN npm run build
FROM nginx as production-stage
RUN mkdir /app
COPY --from=build-stage /app/dist /app
COPY nginx.conf /etc/nginx/nginx.conf
VUE_APP_FOO
is stored and accessible via Node's process.env
objected and seems to be passed in at build time.
And my docker-compose.yml:
version: '3.5'
services:
ms-sql-server:
image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
ports:
- "1430:1433"
api:
image: # omitted (pulled from url)
restart: always
depends_on:
- ms-sql-server
environment:
DBServer: "ms-sql-server"
ports:
- "50726:80"
client:
image: # omitted(pulled from url)
restart: always
environment:
- VUE_APP_BAR="BAR"
depends_on:
- api
ports:
- "8080:80"
When I ssh into the client container with docker exec -it <container_name> /bin/bash
, the VUE_APP_BAR variable is present with the value "BAR". But the variable is not stored in the process.env
object in my Vue application. It seems like something odd is happening with Node and it's environmental variables. It's like it's ignoring the container environment.
Is there anyway for me to access the container level variables set in docker-compose.yml inside my Vue.js application? Furthermore, is there anyway to pass those variables as arguments with docker-compose up
? Let me know if you need any clarification/more information.