1.創建一個后台運行 ubuntu
容器
root@haima-PC:/home/haima/Desktop# docker run -d --name ubuntu-lnmp ubuntu
bf243aabfe110f1aed17a6298c5dbe33df2d023e18fa2f1e1cdb9682d289f710
2.進入容器
root@haima-PC:/home/haima/Desktop# docker exec -it ubuntu-lnmp /bin/bash
root@bf243aabfe11:/# cd /home
root@bf243aabfe11:/home# ls
root@bf243aabfe11:/home# mkdir test
root@bf243aabfe11:/home# ls
test
3.退出容器 exit
4.查看所有的container,包括運行中的,以及未運行的或者說是沉睡鏡像,則運行:
docker ps -a
root@haima-PC:/home/haima/Desktop# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bf243aabfe11 ubuntu "/bin/bash" 5 minutes ago Up 5 minutes ubuntu-lnmp
d4d18c2d2025 centos:v4 "/bin/bash" 2 months ago Up 3 hours centos_env
5.運行已經關閉的容器
root@haima-PC:/home/haima/Desktop# docker start ubuntu-lnmp
ubuntu-lnmp
其中“ubuntu-lnmp”是容器的名稱。這里會后台運行容器,進入容器再退出后,容器也不會關閉
6.進入容器
root@haima-PC:/home/haima/Desktop# docker exec -it ubuntu-lnmp /bin/bash
root@b8cc973c3d4d:/#
- ubuntu-lnmp:要啟動的container的名稱
- /bin/bash:在container中啟動一個bash shell
7. 退出container容器
輸入:
exit
或者按鍵:
Ctrl + D