How to pass environment variables to RUN
command in Dockerfile? In my scenario, I want to pass env variables to RUN
command which runs a script & uses these variables?
.env
NAME=John
script.sh
#!/bin/sh
echo $NAME
Dockerfile
FROM alpine:3.14
COPY . .
RUN chmod +x script.sh
RUN ./script.sh
docker-compose.yml
version: "3.1"
services:
foo:
container_name: foo
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
How can I pass the NAME
env variable to the last RUN
command in Dockerfile (to be used by the script
executable)?
I am aware of --build-arg
but it is inconvenient when there are 100s of env variables. Even then how can I format the docker compose
command to read all arguments from an env file & pass them as build arguments?