Get previous command in docker container console

Viewed 2880

Docker-toolbox is installed on the windows machine. I go into the container, for example: docker exec -it web / bin / sh I can enter commands there.

How to access the history of input commands inside a container? In all consoles, this is done using the up arrow key, here when you press this key, ^ [[A.

How to look at the history or at least call the previous command?

2 Answers

As @DavidMaze pointed out, regular shell located in /bin/sh doesn't have the history feature unlike bash located (simply put) in /bin/bash

related threads can be found here and here, and a more detailed explanation about the difference between the two can be found here

Usage:

when starting fresh container:

docker run -it <imagename:tag> /bin/bash
docker run -it --entrypoint /bin/bash imagename:tag

when connecting to existing container:

docker exec -it <containerid or containername> /bin/bash

The easier way is to type the command "bash" and then you'll be in bash with previous commands history.

Related