La última vez que lo comprobé, cuando hice esto:
FROM x:latest ENV foo 'bar' FROM y:latest RUN echo "$foo"entonces "echo $foo" estaba vacío. ¿Hay alguna forma de conservar las variables ENV en las compilaciones de varias etapas?
Un argumento de construcción podría funcionar para usted en este caso. El usuario no podrá anularlo y no estará disponible en el contenedor, pero aparte de eso, creo que encaja.
FROM alpine ARG FOO RUN echo first step FOO is $FOO FROM alpine ARG FOO RUN echo second step FOO is $FOO Para compilar, debe pasar --build-arg con un valor.
$ docker build --build-arg FOO=bar . Step 1/6 : FROM alpine ---> 055936d39205 Step 2/6 : ARG FOO ---> Running in 3f5f18206d06 Removing intermediate container 3f5f18206d06 ---> 2b82e4b958f7 Step 3/6 : RUN echo first step FOO is $FOO ---> Running in c0256dfe286d first step FOO is bar Removing intermediate container c0256dfe286d ---> 79286b74611f Step 4/6 : FROM alpine ---> 055936d39205 Step 5/6 : ARG FOO ---> Running in 9fc20546619f Removing intermediate container 9fc20546619f ---> 30325962d73a Step 6/6 : RUN echo second step FOO is $FOO ---> Running in a8906382909a second step FOO is bar Removing intermediate container a8906382909a ---> 521dbbfa398b Successfully built 521dbbfa398b