1

I would like to Dockerize my existing vuejs app for staging , production and I used multi staged approach to create my app container and I'm using Ubuntu 18.04 and this is my,

Dockerfile

# build stage
FROM node:lts-alpine as build-stage

LABEL maintainer="servers@xpl.com"

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . ./

RUN npm run build

# production stage
FROM nginx:stable-alpine

LABEL maintainer="servers@xpl.com"

COPY --from=build-stage /app/dist/ /app/dist/

COPY nginx/nginx.conf /etc/nginx/

EXPOSE 80

I don't want to create docker-compose.yml file to assign anything and my question would be like , Create .env file with hardcoded values.

i.e

VUE_APP_API_ENDPOINT_DOMAIN=VUE_APP_API_ENDPOINT_DOMAIN

1 .When running npm run build it'll put VUE_APP_API_ENDPOINT_DOMAIN in the dest files.

2 .We need to know which file. Probably index.html I believe.

3 .We create entry-point.sh script will get all env variables starting with VUE_APP_ and take it's value. And then using sed command we find and replace those hard coded variable placeholders in index.html. And finally start Nginx.

I was stuck on step 3.

4
  • 1
    Your question isn't very clear. Can you clarify it? Also, what have you tried and why didn't it work? Also, the whole thing may be solved with the envsubst command.
    – Matthew
    Feb 12 '20 at 12:51
  • I need to create my existing vue app on docker to deploy it to production so for that I created my Dockerfile which is included in top and now my question is how can I pass env values ? so I created a file called .env to hard coded env values to it will also build during npm build command then I can use sed command to find and replace with actual value . this is the scenario how can I do that ?
    – soldier
    Feb 13 '20 at 7:17
  • The ENV instruction. If you just need an environment variable defined when the container is run, then you can do that when running the container via docker-compose or the docker run command.
    – Matthew
    Feb 13 '20 at 12:40
  • I need to do the 3rd step in my question ``` 3 .We create entry-point.sh script will get all env variables starting with VUE_APP_ and take it's value. And then using sed command we find and replace those hard coded variable placeholders in index.html. And finally start Nginx. ```
    – soldier
    Feb 25 '20 at 7:32
1

While it's not clear what your trying to do (the script you have so far for the bit you are having trouble with would probably be handy), I think you are essentially just trying to parse your environment and manipulate the variables at the start of your script?

I don't see why add something like this to the first line of your script wouldn't work:

eval $(typeset -p | grep -E 'declare -x VUE_APP_' | sed -e 's#declare -x VUE_APP_#export VUE_APP_#g')

But then I also don't know what shell you're running or anything else about the container, so I'm not sure..

1
  • thanks @hvindin
    – soldier
    Feb 29 '20 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.