# Tips Docker: Keep your bash history

> I’m starting by heavily using docker containers for developing, testing and reviewing web applications. There was one thing that bugged me for a long time: the fact that I lost \[…\]

Source: https://antistatique.net/en/blog/tips-docker-keep-your-bash-history

Category: Development

# Tips Docker: Keep your bash history

Author(s)

[

![Gilles](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Gilles-300x300.jpg)



](/en/agence/gilles)

[Gilles](/en/agence/gilles)12 November 2019

I'm starting by heavily using docker containers for developing, testing and reviewing web applications.

There was one thing that bugged me for a long time: the fact that I lost the history of commands I typed in the shell (bash) of the containers each time I stopped/restarted them. I don't have a good memory and don't like to repeat myself. Also, I'm constantly searching in my history (with `history|grep thing` or `CTRL+R`) and wasn't able to do it correctly in a container.

I will present you two solutions to resolve this annoying issue.

## Share the .bash\_history file with the host (docker-compose)

The idea is simple: store bash history on the host and bind-mount this file into the container.

In the following example, I use a file named `.docker_bash_history` that I stored in my home directory. **Important** the file must exist before mounting it.

You can achieve this with the following `docker-compose.yml` example file:

```
<script src="https://gist.github.com/gido/9b7e323571cf61820bd4baef92e30861.js?file=docker-compose.example1.yml "></script>
```

One advantage of this approach is that the bash history can be shared between all your containers. You can also bind-mount your `.bash_history` file of the host instead of using a dedicated file (`.docker_bash_history`).

## Store .bash\_history into a named volume

Another way is to persist the `.bash_history` into a named volume and rely on the `HISTFILE` environment variable to specify where the history file is:

```
<script src="https://gist.github.com/gido/9b7e323571cf61820bd4baef92e30861.js?file=docker-compose.example2.yml "></script>
```

## Without docker-compose

The same approach can be used without `docker-compose`. Eq:

`$ docker run -it -v ~/.docker_bash_history:/root/.bash_history ubuntu bash`

That's it !

## More articles

Author(s)

[

![Anthony](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2024/11/anthony-1-300x300.png)



](/en/agence/anthony-salamone)

[Anthony](/en/agence/anthony-salamone)28 September 2026

### [Smashing Conference Freiburg 2026](/en/blog/smashing-conference-freiburg-2026)

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

Back in Freiburg for Smashing Conference 2026: AI and design systems, deeply technical CSS and HTML, and more human talks about teams and mindset. Here's what we took away.

[

![Smashing Conference Freiburg 2026 poster](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/assets/blog/smashing-2026.png)



](/en/blog/smashing-conference-freiburg-2026)

Author(s)

[

![Akira](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2025/03/akira-small-300x300.jpg)



](/en/agence/akira-kamata)

[Akira](/en/agence/akira-kamata)22 July 2026

### [Making of : “La nuit des Losers”](/en/blog/making-of-la-nuit-des-losers)

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

lanuitdeslosers.ch, built fast: paper wireframes, a bold hand-drawn identity, then Claude Code to prototype and ship. A mouse-tracking hero animation, a bowling game made of sponsor logos, and a few bugs we’re keeping.

[

![Making of : “La nuit des Losers”](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/05/La-nuit-des-Losers-Teaser-1-768x576.png)



](/en/blog/making-of-la-nuit-des-losers)

Author(s)

[

![Pierre](https://images.statique.ch/t/w_750,h_750,c_fill,f_jpeg,q_70/wp/app/uploads/2020/12/Pierre-300x300.jpg)



](/en/agence/pierre)

[Pierre](/en/agence/pierre)7 July 2026

### [Dark mode: necessity or trend](/en/blog/dark-mode-necessity-or-trend)

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

Nous faisons le tri entre idées reçues, réalités techniques et bonnes pratiques de design.

[

![Dark mode: necessity or trend](https://images.statique.ch/t/w_750,h_500,c_fill,f_jpeg,q_70/wp/app/uploads/2026/07/1-768x384.png)



](/en/blog/dark-mode-necessity-or-trend)
