docker run -it imageID [cmd]
这个是用镜像产生一个容器,并且和cmd程序做交互,-i表示交互式的,表示[cmd]是一个有用户输入的程序,比如/bin/bash 和 python 等等。
-t 产生一个终端。所以说有-i就必须有-t,不然怎么输入。
docker创建容器
$ docker run -it ubuntu:latest /bin/bash
docker查看启动的容器
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
240f22e326f5 ubuntu:latest "/bin/bash" 52 minutes ago Up 4 minutes
docker启动容器
$ sudo docker start 240f22e326f5
240f22e326f5
docker进入到容器内部
$ sudo docker exec -it 240f22e326f5 /bin/bash
docker查看所有容器
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
b9a598568e49 ubuntu:latest "/bin/bash" 45 minutes ago Exited (127) 7 minutes ago
62de3ec6be08 ubuntu:latest "/bin/bash" 57 minutes ago Exited (0) 45 minutes ago
4d284a0bddee ubuntu:latest "/bin/bash" 4 hours ago Exited (0) 57 minutes ago
38f930572d5c ubuntu:latest "/bin/bash" 5 hours ago Exited (130) 4 hours ago
0e24d1276a20 ubuntu:latest "/bin/bash" 5 hours ago Exited (127) 5 hours ago
240f22e326f5 ubuntu:latest "/bin/bash" 6 hours ago Up 6 hours
8414455bab46 ubuntu:latest "/bin/bash" 18 hours ago Exited (0) 6 hours ago
28e56eda9cad ubuntu:latest "/bin/bash" 19 hours ago Exited (100) 18 hours ago
docker删掉不用的docker容器
$ sudo docker container rm 62de3ec6be08 4d284a0bddee 38f930572d5c 0e24d1276a20 8414455bab46 28e56eda9cad
docker获取busybox image
$ sudo docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
7e5209d2300f: Pull complete
Digest: sha256:34c3559bbdedefd67195e766e38cfbb0fcabff4241dbee3f390fd6e3310f5ebc
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest
docker查看本地的images
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 829374d342ae 5 days ago 1.24MB
ubuntu latest 17c3d5693947 2 months ago 3.22GB
docker运行busybox输出Hello world
$ sudo docker run busybox echo 'Hello world'
hello world
docker交互模式运行container基于busybox image
$ sudo docker run -it busybox
/
|