Docker and .bash_history

前端 未结 6 1825
感动是毒
感动是毒 2020-12-30 19:58

Is there any way to share a .bash_history volume with a docker container so that everytime I go into a shell I have my bash history available for scrolling thro

6条回答
  •  星月不相逢
    2020-12-30 20:29

    My solution is useful when:

    • you don't want to share your local .bash_history with .bash_history in your container
    • you use other shell (like fish shell) but you want to save .bash_history between your builds
    • you don't want to commit .bash_history to git repo but you want to create it automatically inside same directory when a container starts

    I assume file structure to be:

    docker-compose.yml
    docker/
       \--> bash/
          \--> .bashrc
          \--> .bash_history
    

    docker-compose.yml

    web-service:
      build: .
      volumes:
      - ./docker/bash/.bashrc:/home/YOUR_USER_NAME/.bashrc
      - ./docker/bash:/home/YOUR_USER_NAME/bash
    

    ./docker/bash/.bashrc - it will automatically create .bash_history:

    export HISTFILE=~/bash/.bash_history
    touch $HISTFILE
    

    Optionally, you can add to .gitignore:

    docker/bash/.bash_history
    

提交回复
热议问题