Does Docker USER source .bashrc before running commands?

I have a Docker file where I’m running along the lines of:

FROM centos:6.7
...
...
RUN useradd -ms /bin/bash my_user \
 && echo "my_user:docker" | chpasswd \
 && echo "my_user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
 && chown my_user:my_user /home/my_user \
 && chmod 755 /home/my_user \
 && mkdir -p /home/my_user/.ssh
...
RUN echo "export HELLO=WORLD" >> /home/my_user/.bashrc
...
USER my_user
ENV FLASK_APP=/path/to/my/app.py
CMD ["flask", "run", "--host", "0.0.0.0"]

The Flask server, upon getting the correct web request, simply executes the following:

  • Detect AWS host environment from within a Docker Container
  • How to get the docker container logs using docker-java client library
  • Docker for windows container is not starting with -m 4g but works fine with -m 3g
  • Restart failed Selenium browser
  • utility for use docker instead of classic setup ( wamp, mamp, lamp)
  • Is 2 the minimum number of instances to properly deploy a container on AWS?
  • procedure = subprocess.Popen("/my/cool/program", shell=False)
    

    However, the program fails to find the HELLO environment variable. When I force the environment into the command by doing

    env_dict = {
        'HELLO': 'WORLD'
    }
    
    procedure = subprocess.Popen("/my/cool/program", shell=False, env=env_dict)
    

    It works without issue. This is making me believe that the issue is that when docker runs the CMD as the user selected with USER, it doesn’t first source that’s user’s environment properly.

    Is that true? If so, is there any good way around it? I’d like to avoid double declaring all my env variables in both the .bashrc and in the Flask app.

  • Docker for Mac: x509: certificate signed by unknown authority error
  • Assign network aliases dynamically on global deployed services in a docker stack
  • Setting Rails Environment for Apache by Environment Variable
  • How to connect docker containers in separate deployments on the same host machine using docker-compose?
  • Recommend way to Artisan on Docker
  • Bad log time in Docker
  • One Solution collect form web for “Does Docker USER source .bashrc before running commands?”

    Try running it with bash as your command:

    CMD ["bash", "-c", "flask run --host 0.0.0.0"]
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.