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:

  • Docker Jenkins Integration
  • Passing a docker container's generated name to another container in docker-compose
  • How to get back to life docker container?
  • 'docker-compose' not found error when command was executed in Jenkins job
  • How to set image stored path in docker registry?
  • Cleaning docker containers via jenkins shell on slave
  • 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.

  • Failed to connect to 192.168.99.100 port 8888: Timed out
  • Cache PIP packages in dockerfile
  • How to mount volumes to global volume in Docker Swarm and bundle
  • Is it possible to create image from file on docker host using docker API?
  • Reverse proxy nginx with Docker
  • Files in the folder don't appear on the host after mounting to container
  • 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.