Docker and .bash_history

2019-01-23 23:35发布

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 through?

Would be awesome to be able to do the same thing with IPython too.

3条回答
看我几分像从前
2楼-- · 2019-01-23 23:59

It is the example from the documentation about volume: Mount a host file as a data volume:

docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash

This will drop you into a bash shell in a new container, you will have your bash history from the host and when you exit the container, the host will have the history of the commands typed while in the container.

查看更多
smile是对你的礼貌
3楼-- · 2019-01-24 00:15

To keep IPython history, you can set the IPYTHONDIR environment variable to somewhere within your mapped volume.

The docker-compose.override.yml would look like this:

version: '2'
services:
  some-service:
    environment:
      - IPYTHONDIR=/app/.ipython
    volumes:
      - .:/app
查看更多
Emotional °昔
4楼-- · 2019-01-24 00:23

In your docker-compose.override.yml:

version: '2'
services:
  whatever:
    …
    volumes:
      - …
      - ~/.bash_history:/root/.bash_history
查看更多
登录 后发表回答