Структура папок следующая:
/
/account
Dockerfile
docker-compose.yml
.env
.env 文件:
TEST=test
码头工人-compose.yml:
version: '3'
services:
account:
env_file:
- .env
build:
context: account/src
dockerfile: Dockerfile
args:
ONE: ${TEST}
TWO: $TEST
THREE: 3
environment:
- FOUR=${TEST}
- FIVE=$TEST
- SIX=6
command: some command
码头文件:
FROM node:12.19.0-alpine3.11
WORKDIR /app
RUN echo ONE $ONE
RUN echo TWO $TWO
RUN echo THREE $THREE
RUN echo FOUR $FOUR
RUN echo FIVE $FIVE
RUN echo SIX $SIX
.. whatever
EXPOSE $APP_PORT
CMD ["some", "command"]
在终端我看到:
Step 3/19 : RUN echo ONE $ONE
---> Running in caa4cd247d5d
ONE
Removing intermediate container caa4cd247d5d
---> 35470ab440be
Step 4/19 : RUN echo TWO $TWO
---> Running in 23ac6fd171b7
TWO
Removing intermediate container 23ac6fd171b7
---> e45af7802515
Step 5/19 : RUN echo THREE $THREE
---> Running in 562ad0182074
THREE
Removing intermediate container 562ad0182074
---> f2e8cbe870d0
Step 6/19 : RUN echo FOUR $FOUR
---> Running in 9e3217e4731b
FOUR
Removing intermediate container 9e3217e4731b
---> d138ea278878
Step 7/19 : RUN echo FIVE $FIVE
---> Running in aa1be66d515c
FIVE
Removing intermediate container aa1be66d515c
---> 1bb0b844cd41
Step 8/19 : RUN echo SIX $SIX
---> Running in 53551d8861b0
SIX
同时,应用程序本身可以看到环境变量(并且看不到参数)。
如何将环境变量传递给 Dockerfile?
码头文件: