'docker ENV vs RUN export

Let's say I want combine these commands

RUN command_1
ENV FOO bar
RUN command_2

into

RUN command_1 && export FOO=bar && command_2

and was wondering if setting the variable with RUN export vs ENV was equivalent.

In other words, is there a difference between these commands in a Dockerfile?

ENV FOO bar

vs

RUN export FOO=bar


Solution 1:[1]

I think this can be helpful

RUN echo "export FOO=bar" >> /etc/bash.bashrc

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Xu Chen