docker images 查看镜像(本地的镜像或者远程下载的镜像)
[root@VM-0-2-centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 7baf28ea91eb 3 days ago 133MB
keking/kkfileview latest 8dcf02dd90c7 4 months ago 1.09GB
java 8 d23bdf5b1b1b 3 years ago 643MB
docker ps 查询正在运行的容器
[root@VM-0-2-centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
976f00bb7d26 nginx "/docker-entrypoint.…" 38 hours ago Up 38 hours 0.0.0.0:81->80/tcp hungry_pascal
[root@VM-0-2-centos ~]#
docker ps -a 查询docker 里面有多少个容器(运行的和未运行的)
[root@VM-0-2-centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
976f00bb7d26 nginx "/docker-entrypoint.…" 39 hours ago Up 39 hours 0.0.0.0:81->80/tcp hungry_pascal
dcf3e733f670 keking/kkfileview "java -Dfile.encodin…" 2 months ago Created stupefied_easley
23e3cede784d keking/kkfileview "java -Dfile.encodin…" 2 months ago Created recursing_cohen
83741d122487 keking/kkfileview "java -Dfile.encodin…" 2 months ago Created priceless_swartz
35ea12b36057 keking/kkfileview "java -Dfile.encodin…" 2 months ago Created hardcore_kirch
[root@VM-0-2-centos ~]#
docker 中容器的删除, 根据容器的id 进行删除
[root@VM-0-2-centos ~]# docker rm 35ea12b36057
35ea12b36057
[root@VM-0-2-centos ~]#
docker 中image(镜像的删除)
docker rmi 镜像Id
[root@VM-0-2-centos ~]# docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 7baf28ea91eb 3 days ago 133MB
keking/kkfileview latest 8dcf02dd90c7 4 months ago 1.09GB
java 8 d23bdf5b1b1b 3 years ago 643MB
[root@VM-0-2-centos ~]# docker rmi 8dcf02dd90c7
Untagged: keking/kkfileview:latest
Untagged: keking/kkfileview@sha256:b6f76aa5f56224ebc4a481afb2ae7f366e8e42a08daa255d30d92ff74fa50f38
Deleted: sha256:8dcf02dd90c7b3b6811be60f353ae08f4a76b85cc12d072ba6aa1555c81e38e4
Deleted: sha256:a4f5def36fdaaa433f576d15a909b365577b3cb7282767a70543190e36051089
Deleted: sha256:954731ae8a60c3a5abc9edc9f48a0b81544b629413b70efaeb3ea8577fefb910
Deleted: sha256:92ee0570d0ad3a30f5e9b1ff301e8adb367c0da03d79f84332c1172382c8b654
Deleted: sha256:be38051dda60e749f9d5ed85797298f29189687892a8a6bc53ca03a60559662c
Deleted: sha256:88bebd8434e1404be18216a8570c5d271def87d51cb78e5bb6c5a7c17a64f55e
Deleted: sha256:54a124f068afcdda2f8640596bfab1ffb1589d6dc31214e61824362303dd4112
Deleted: sha256:d22cfd6a8b16689838c570b91794ed18acc752a08a10bce891cc64acc1533b3f
[root@VM-0-2-centos ~]# docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 7baf28ea91eb 3 days ago 133MB
java 8 d23bdf5b1b1b 3 years ago 643MB
[root@VM-0-2-centos ~]#
获取镜像(如果没有设置版本,默认是最新稳定版)
docker pull nginx
[root@VM-0-2-centos ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
6ec7b7d162b2: Pull complete
bbce32568f49: Pull complete
5928664fb2b3: Pull complete
a85e904c7548: Pull complete
ac39958ca6b1: Pull complete
Digest: sha256:31de7d2fd0e751685e57339d2b4a4aa175aea922e592d36a7078d72db0a45639
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
启动镜像 nginx,(下面81端口是主机的端口,也就是是服务器的端口,80是容器的端口,-d 是在后台运行。)
docker run -d -p 81:80 nginx
[root@VM-0-2-centos ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@VM-0-2-centos ~]# docker run -d -p 81:80 nginx
78b323b556d3e71814594d803e69202b70c0979b3b6bde60198ec523bfe89fdc
进入镜像
docker exec -it 3adfac31653d bash
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3adfac31653d 7baf28ea91eb "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp tender_cannon
[root@VM-0-2-centos ~]# docker exec --help
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
Options:
-d, --detach Detached mode: run command in the background
--detach-keys string Override the key sequence for detaching a container
-e, --env list Set environment variables
--env-file list Read in a file of environment variables
-i, --interactive Keep STDIN open even if not attached
--privileged Give extended privileges to the command
-t, --tty Allocate a pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
[root@VM-0-2-centos ~]# docker exec -it 3adfac31653d bash
root@3adfac31653d:/# ls