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:

  • How does ENTRYPOINT Docker directive react when extending images
  • Can I mount docker host directory as copy on write/overlay?
  • Docker Port Detection
  • Docker node development environment on windows
  • dotnet core on docker performance
  • What is the difference between running an application on ec2-server and running an application on top of docker on ec2-server?
  • 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.

  • MongoDB Docker Windows dev env. linux production env. possible solution?
  • “Empty reply from server” when trying to run webpack-dev-server inside a docker container with docker-compose on windows running docker-toolbox
  • copy the file from host to docker container prior to run webserver in container
  • Docker portability issues with locally saved images
  • Detect if my app runs in Azure
  • Gitlab docker registry pull failed EOF
  • 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.