How to set bash aliases for docker containers in Dockerfile?

I am new to docker. I found that we can set environment variables using ENV instruction in the Dockerfile. But how does one set bash aliases for long commands in Dockerfile?

  • How to tail docker into jq?
  • Docker bash'ing with find
  • exec not found using Dockerfile ENTRYPOINT
  • Docker rm does not remove my container if the physical machine dies
  • Get Environment Variable from Docker Container
  • bash regular expressions to get docker container port number
  • Do I need a private docker registry?
  • execSync compilation failed with npm 3
  • docker pull failed. manifest invalid: manifest invalid - artifactory
  • Deploying multi-docker local setup to AWS using Elastic Beanstalk
  • How do i migrate mysql data directory in docker container?
  • node can't find modules that exists in parent node_modules folder
  • 2 Solutions collect form web for “How to set bash aliases for docker containers in Dockerfile?”

    Basically like you always do, by adding it to the users .bashrc:

    FROM foo
    RUN echo 'alias hi="echo hello"' >> ~/.bashrc

    As usual this will only work for interactive shells:

    docker build -t test .
    docker run -it --rm --entrypoint /bin/bash test hi
    /bin/bash: hi: No such file or directory
    docker run -it --rm test bash
    $ hi

    For non-interactive shells you should create a small script and put it in your path, i.e.:

    echo '#!/bin/bash\necho hello' > /usr/bin/hi
    chmod +x /usr/bin/hi

    You can use entrypoint, but it will not work for alias, in your Dockerfile:

    ADD dev/ /opt/
    ENTRYPOINT ["/opt/"]


    set -e
    function dev_run()
    export -f dev_run
    exec "$@"

    (Quick copy/paste, sorry)

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.