连接容器的 shell

docker container run -it 创建一个容器并进入交互式模式

  1. ~ docker container run -it busybox sh
  2. / #
  3. / #
  4. / # ls
  5. bin dev etc home proc root sys tmp usr var
  6. / # ps
  7. PID USER TIME COMMAND
  8. 1 root 0:00 sh
  9. 8 root 0:00 ps
  10. / # exit

docker container exec -it 在一个已经运行的容器里执行一个额外的command

  1. ~ docker container run -d nginx
  2. 33d2ee50cfc46b5ee0b290f6ad75d724551be50217f691e68d15722328f11ef6
  3. ~
  4. ~ docker container exec -it 33d sh
  5. #
  6. #
  7. # ls
  8. bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
  9. #
  10. # exit
  11. ~