Answers: <p>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 <em>think</em> you are essentially just trying to parse your environment and manipulate the variables at the start of your script?</p>
  
  <p>I don't see why add something like this to the first line of your script wouldn't work:</p>
  
  <pre><code>eval $(typeset -p | grep -E 'declare -x VUE_APP_' | sed -e 's#declare -x VUE_APP_#export VUE_APP_#g')
  </code></pre>
  
  <p>But then I also don't know what shell you're running or anything else about the container, so I'm not sure..</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-02-29T08:57:03.883Z
Answers: thanks @hvindin
Answers: soldier
Answers: CC BY-SA 4.0
Answers: 2020-02-29T05:00:45.897Z
Answers: 2020-02-29T05:00:45.897Z
Answers: hvindin
Body: <p>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,</p>
  <h3>Dockerfile</h3>
  <pre><code># build stage
  FROM node:lts-alpine as build-stage
  
  LABEL maintainer=&quot;servers@xpl.com&quot;
  
  WORKDIR /app
  
  COPY package*.json ./
  
  RUN npm install
  
  COPY . ./
  
  RUN npm run build
  
  # production stage
  FROM nginx:stable-alpine
  
  LABEL maintainer=&quot;servers@xpl.com&quot;
  
  COPY --from=build-stage /app/dist/ /app/dist/
  
  COPY nginx/nginx.conf /etc/nginx/
  
  EXPOSE 80
  </code></pre>
  <p>I don't want to create <code>docker-compose.yml</code> file to assign anything and my question would be like , Create <code>.env</code> file with hardcoded values.</p>
  <p><strong>i.e</strong></p>
  <pre><code>VUE_APP_API_ENDPOINT_DOMAIN=VUE_APP_API_ENDPOINT_DOMAIN
  </code></pre>
  <p>1 .When running npm run build it'll put VUE_APP_API_ENDPOINT_DOMAIN in the dest files.</p>
  <p>2 .We need to know which file. Probably index.html I believe.</p>
  <p>3 .We create entry-point.sh script will get all env variables starting with <code>VUE_APP_</code> and take it's value. And then using <strong><code>sed</code></strong> command we find and replace those hard coded variable placeholders in index.html.
  And finally start Nginx.</p>
  <p><strong>I was stuck on step 3.</strong></p>
  
Comments: CC BY-SA 4.0
Comments: 2020-02-12T12:51:05.527Z
Comments: 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](https://linux.die.net/man/1/envsubst) command.
Comments: Matthew
Comments: CC BY-SA 4.0
Comments: 2020-02-13T07:17:07.770Z
Comments: 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 ?
Comments: soldier
Comments: CC BY-SA 4.0
Comments: 2020-02-13T12:40:34.540Z
Comments: The [ENV](https://docs.docker.com/engine/reference/builder/#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.
Comments: Matthew
Comments: CC BY-SA 4.0
Comments: 2020-02-25T07:32:37.233Z
Comments: 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.  ```
Comments: soldier
Tags: <docker><dockerfile><shell-script><bash>
Title: create entry-point script to get all env variables starting with VUE_APP_ and take it's value
UserDisplayName: soldier
ThreadText: # create entry-point script to get all env variables starting with VUE_APP_ and take it's value
  
  (Asked by: username_0 on 2020-02-12)
  
  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.**
  
  **Tags:** docker, dockerfile, shell-script, bash
  
  > **Comments:**
  > **username_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](https://linux.die.net/man/1/envsubst) command.  
  > **username_0**: 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 ?  
  > **username_1**: The [ENV](https://docs.docker.com/engine/reference/builder/#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.  
  > **username_0**: 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.  ```  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-02-29. Score: 1 | Accepted answer
  
  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..
  
  > **Comments:**
  > **username_0**: thanks @username_2  
  
  ---
  
  