1.查看docker的版本号:
[root@docker web]# docker -v
Docker version 20.10.12, build e91ed57
[root@docker web]# docker --version
Docker version 20.10.12, build e91ed57
2.查看docker里的镜像文件
[root@docker web]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 0e403e3816e8 8 days ago 113MB
nginx latest c919045c4c2b 10 days ago 142MB
3.查看docker里某个镜像文件的使用数
[root@docker web]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 16452 [OK]
bitnami/nginx Bitnami nginx Docker Image 120 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 33
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 16 [OK]
rancher/nginx-ingress-controller 10
ibmcom/nginx-ingress-controller Docker Image for IBM Cloud Private-CE (Commu… 4
bitnami/nginx-ldap-auth-daemon 3
bitnami/nginx-exporter 2
circleci/nginx This image is for internal use 2
vmware/nginx 2
4.从镜像仓库拉取镜像
[root@docker web]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
不指定版本号默认拉取最新的版本
5.查看启动的docker容器(-a表示查看所有的docker容器)
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178670998f2d nginx "/docker-entrypoint.…" 35 minutes ago Up 35 minutes 80/tcp, 0.0.0.0:700->10/tcp, :::700->10/tcp sswww
a7912c6282da nginx "/docker-entrypoint.…" 42 minutes ago Up 42 minutes 80/tcp, 0.0.0.0:7780->10/tcp, :::7780->10/tcp zsswww
99c44b78eab3 nginx "/docker-entrypoint.…" 44 minutes ago Up 44 minutes 0.0.0.0:7790->80/tcp, :::7790->80/tcp zswww
cd8f32216147 redis "docker-entrypoint.s…" About an hour ago Up 57 minutes 6379/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp zsw
[root@docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178670998f2d nginx "/docker-entrypoint.…" 35 minutes ago Up 35 minutes 80/tcp, 0.0.0.0:700->10/tcp, :::700->10/tcp sswww
a7912c6282da nginx "/docker-entrypoint.…" 42 minutes ago Up 42 minutes 80/tcp, 0.0.0.0:7780->10/tcp, :::7780->10/tcp zsswww
99c44b78eab3 nginx "/docker-entrypoint.…" 44 minutes ago Up 44 minutes 0.0.0.0:7790->80/tcp, :::7790->80/tcp zswww
cd8f32216147 redis "docker-entrypoint.s…" About an hour ago Up 57 minutes 6379/tcp, 0.0.0.0:8080->80/tcp, :::8080->80/tcp zsw
992390d77b27 jcdemo/flaskapp "python /src/app.py" 38 hours ago Exited (255) 26 hours ago 5000/tcp, 0.0.0.0:8030->80/tcp, :::8030->80/tcp sc_flask_1
9d955d3f6e1a redis "docker-entrypoint.s…" 38 hours ago Exited (255) 26 hours ago 6379/tcp, 0.0.0.0:8020->80/tcp, :::8020->80/tcp sc_redis_1
aece2dbca9e4 nginx "/docker-entrypoint.…" 39 hours ago Exited (255) 2 hours ago 0.0.0.0:8090->80/tcp, :::8090->80/tcp sc_nginx_3
5e097ce592d3 nginx "/docker-entrypoint.…" 39 hours ago Exited (255) 26 hours ago sc_nginx_2
368d7de3d75e nginx "/docker-entrypoint.…" 39 hours ago Exited (0) 39 hours ago jovial_mestorf
b71d7533693a hello-world "/hello" 40 hours ago Exited (0) 40 hours ago great_mclaren
6.创建容器并且启动容器
[root@docker ~]# docker run -d -p 822:80 --name zhangsw1 nginx
47b7807e99d0b4e0b74c17e9a8c9a7a7117b467ae8be8bbb1a733e97e4242cd0
7.停止某个容器
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47b7807e99d0 nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:822->80/tcp, :::822->80/tcp zhangsw1
178670998f2d nginx "/docker-entrypoint.…" 40 minutes ago Up 40 minutes 80/tcp, 0.0.0.0:700->10/tcp, :::700->10/tcp sswww
[root@docker ~]# docker stop zhangsw1
zhangsw1
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178670998f2d nginx "/docker-entrypoint.…" 40 minutes ago Up 40 minutes 80/tcp, 0.0.0.0:700->10/tcp, :::700->10/tcp sswww
8.删除某个容器
[root@docker ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178670998f2d nginx "/docker-entrypoint.…" 40 minutes ago Up 40 minutes 80/tcp, 0.0.0.0:700->10/tcp, :::700->10/tcp sswww
[root@docker ~]# docker rm sswww
Error response from daemon: You cannot remove a running container 178670998f2d477e06247270203fd8afe276d7e8fff5bfd5eb36f345cc28cf2b. Stop the container before attempting removal or force remove
提示错误表示不能删除正在运行的容器
先停止运行再删除
[root@docker ~]# docker stop sswww
sswww
[root@docker ~]# docker rm sswww
sswww
9.进入某个容器
docker exec -it sc_nginx2 /bin/bash
--interactive , -i
交互式方式进入容器
--tty , -t
开启一个终端
sc_nginx
容器名字
/bin/bash
进入容器执行的程序
exit
退出容器
10.查看容器的详细信息
docker container inspect zsw1