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/
CMD ["flask", "run", "--host", ""]

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

  • meteor up listen tcp bind: address already in use
  • Connect to mysql in a docker container from the host
  • How to use additional parameters for PhantomJS in a Docker container?
  • Is it possible to let ansible print each statement?
  • Communicating between a windows and linux docker container on the same host
  • Adding a backup crontab into a docker container
  • 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.

  • Error while sharing local drive(volume) with docker for windows
  • get docker log stream in correct order
  • Jenkins getting test results from docker slave
  • Link docker-compose to local docker daemon
  • Can Docker 1.12 in “swarm mode” provide “a single, virtual Docker host”?
  • Docker Swarm Service Networking
  • 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"]
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.