🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
在上一章中,我们学习了如何安装Docker,如何确保Docker守护进程正常运行。在本章中,我们将迈出使用docker的第一步,学习第一个docker容器。本章还会介绍如何与Docker交互。 ### 运行我们第一个容器 docker run -it ubuntu /bin/bash - -i 以STDIN连接到容器 - -t 给创建的容器分配 一个tty终端 容器命名 docker run --name bob_the_container -it Ubuntu /bin/bash 启动容器 docker start bob_the_container 使用container ID 启动容器 docker start aa3f65f0f4e 附着到容器上 docker attach bob_the_container 创建手护式容器 docker run --name bob_the_container -d Ubuntu /bin/sh -c "while true ;do echo 'hello word”; sleep 1; done" - -d 容器在后台运行 查看容器内的进程 docker top bob_the_container Docker 统计信息 docker stats 942fed0e1b5b 更强大的ctop 查看docker信息。[GitHub项目地址](https://github.com/bcicen/ctop) ctop 在容器内部运行进程 docker exxec -d bob_the_container touch /root/test.txt 在容器内运行交互命令 docker exec -it bob_the_container /bin/bash 停止容器 docker stop bob_the_container 自动重启容器 docker run --restart=always --name bob_the_container -d Ubuntu /bin/sh -c "while true ;do echo 'hello word”; sleep 1; done" - --restart=on-failurt:5 Docker自动尝试重启,最多重启5次 查看容器详细信息 docker inspect nifty_wilson 有选择的获取容器信息 docker inspect --format='{{ .State.Running }}' nifty_wilson false 删除容器 docker rm nifty_wilson 删除所有容器 docker rm `docker ps -a -q` - -a 查找所有容器 - -q 只返回容器ID