Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I break a long ENV declaration in Dockerfile?

I have a Dockerfile with an ENV declaration for set of paths to be searched that over time has become somewhat comically long:

ENV SPECIAL_PATHS=/foo/bar:/yada/dada:{... ~20 more .. }:/the/end

I cannot see what is the idiomatic way to break in the documentation. I could, of course, define pieces in multiple ENV lines and then combine, but I'd rather not add yet more layers.

like image 228
Francesco Callari Avatar asked Oct 20 '25 11:10

Francesco Callari


1 Answers

You can use \ to break it up over multiple lines.

FROM alpine:3.8

ENV SPECIAL_PATHS \
/foo/bar:\
/yada/yada:\
/the/end

Here's the env in container run from the resulting image.

$ docker container run --rm env-test env 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=2fae9abd1eea
SPECIAL_PATHS=/foo/bar:/yada/yada:/the/end
HOME=/root
like image 98
King Chung Huang Avatar answered Oct 23 '25 18:10

King Chung Huang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!