Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get previous command in docker container console

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?

like image 935
sveta600 Avatar asked Apr 10 '20 09:04

sveta600


People also ask

How do I view the console of a docker container?

docker logs <container id> will show you all the output of the container run. If you're running it on ECS, you'll probably need to set DOCKER_HOST=tcp://ip:port for the host that ran the container. My container is already stopped. Using the cmd line doing, docker run -d image, it returns me the container id.

What is the docker command to roll back to the previous version of a service?

Use the docker service rollback command to roll back to the previous version of a service. After executing this command, the service is reverted to the configuration that was in place before the most recent docker service update command.


Video Answer


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
like image 62
Noam Yizraeli Avatar answered Oct 22 '22 02:10

Noam Yizraeli


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

like image 30
L01C Avatar answered Oct 22 '22 01:10

L01C