4 ways to get into a container
1. Use docker attach
How to use: docker attach CONTAINER ID
Disadvantages: Multiple window operations will be displayed synchronously, and if one window is blocked, other windows are also blocked, so it is not recommended.
2. Use ssh
How to use: Install ssh sever in the container, and multiple users can enter the container at the same time.
Disadvantage: no research, empty reference link ( why don't need to run ss hd in Docker container ): https://www.oschina.net/translate/why-you-dont-need-to-run-sshd-in- docker?cmp
3. Use nsenter
why:nsenter can access the namespace of another process. To use nsenter, please use the command nsenter --help.
How to use: docker inspect+nsenter
inspect is used to get the process pid of the container. You can use the command sudo docker inspect -f {{.State.Pid}} CONTAINER ID. After getting the pid of the process, we can use nsenter to enter the container with the following command.
sudo nsenter --target 8700 --mount --uts --ipc --net --pid
4. Use docker exec
sudo docker exec --help
sudo docker ps
docker exec -it container id /bin/bash
Reference link:
[1] https://www.cnblogs.com/xhyan/p/6593075.html