docker

 

# 更新系统软件
yum update -y --exclud=kernel*

参数:
--exclud 排除相关软件包

# 镜像 : 创建容器的模板

# 容器 : 创建对外服务的实例

# 仓库 : 存放镜像的地方

## 获取

格式:docker pull [镜像仓库URL]/[命名空间名称]/[仓库名称]:[镜像版本号]

docker pull busybox:latest
docker pull docker.io/library/busybox:latest

URL : docker.io
命名空间: library
仓库名称:busybox
版本号: latest

docker pull registry.cn-hangzhou.aliyuncs.com/alvinos/python:v5

# 登录
docker login [参数] [镜像仓库URL]


# 获取本机镜像
docker images 或 docker image ls [参数]

参数:
-a : 显示所有的镜像(包括临时镜像文件)


[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest dc3bacd8b5ea 6 days ago 1.23MB

REPOSITORY:仓库名称
TAG:版本号(latest:表示最新的版本)
IMAGE ID: 镜像ID
CREATED: 时间段
SIZE: 镜像文件的体积

参数:
-q : 只显示镜像ID


# 推送镜像

docker push [镜像仓库URL]/[命名空间名称]/[仓库名称]:[版本号]
[root@Centos7 docker]# docker push registry.cn-hangzhou.aliyuncs.com/alvinos/py15-nginx:1.19.2
The push refers to repository [registry.cn-hangzhou.aliyuncs.com/alvinos/py15-nginx]
908cf8238301: Pushed
eabfa4cd2d12: Pushed
60c688e8765e: Pushed
f431d0917d41: Pushed
07cab4339852: Pushed
1.19.2: digest: sha256:794275d96b4ab96eeb954728a7bf11156570e8372ecd5ed0cbc7280313a27d19 size: 1362


# 给镜像打TAG
docker tag [原镜像仓库url]/[原镜像命名空间]/[原镜像仓库名称]:[版本号] [新镜像仓库url]/[新镜像命名空间]/[新镜像仓库名称]:[版本号]

docker tag nginx:1.19.2 registry.cn-hangzhou.aliyuncs.com/alvinos/py15-nginx:1.19.2


# 获取镜像的详细信息

docker inspect [镜像ID|镜像名称:版本号]

参数:
-f : 可以使用golang的模板获取所需信息

# 查看镜像历史
docker history [镜像名字:镜像版本号 | 镜像ID]

# 搜索镜像
docker search [所搜索的镜像名称]


[root@Centos7 docker]# docker search python
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
python Python is an interpreted, interactive, objec… 5661 [OK]
django Django is a free web application framework, … 1021 [OK]
pypy PyPy is a fast, compliant alternative implem… 256 [OK]
nikolaik/python-nodejs Python with Node.js 55 [OK]
joyzoursky/python-chromedriver Python with Chromedriver, for running automa… 54 [OK]


列表参数:

NAME:仓库名称
DESCRIPTION: 描述
STARS:收藏个数
OFFICIAL:是否是官方镜像
AUTOMATED: 是否是自构建的镜像

命令行参数:

-f : 过滤
docker search python -f stars=300

# 删除 与 清理镜像

### 删除
docker rmi [镜像名称:版本号 | 镜像ID]

[root@Centos7 docker]# docker rmi busybox
Untagged: busybox:latest
Untagged: busybox@sha256:9f1c79411e054199210b4d489ae600a061595967adb643cd923f8515ad8123d2
Deleted: sha256:dc3bacd8b5ea796cea5d6070c8f145df9076f26a6bc1c8981fd5b176d37de843
Deleted: sha256:8f8e3c7011ee77277dc15d094222824fdc454df7b6828d31bc3bddf07d47ba33


参数:
-f : 强制删除

# 清理镜像
docker image prune [参数]

参数:
-a : [all] 清理所有没有被使用的镜像


# 保存镜像
docker commit [参数] [容器ID | 容器名称:版本号]

参数:

-a : 维护者
-m : 简介
-p : 保存镜像时,镜像暂停运行


# 运行一个容器
docker run [参数] [镜像名称|镜像ID] [执行的命令(默认执行指定的命令)]

参数:
-d : 以守护进程的方式运行
-p : 指定端口映射(格式:宿主主机端口:容器向外暴露的端口)
docker run -d -p 8899:80 nginx:1.19.2
-P : 随机端口映射
docker run -d -P nginx:1.19.2
--name: 指定容器的名称(同一台宿主主机上的docker名称不能重复)
docker run -d --name nginx_name -P nginx:1.19.2
--rm:当一个容器结束了它的生命周期,就立即删除
docker run -d --rm --name nginx_rm nginx:1.19.2
-v: 映射存储卷(可以映射文件及文件夹)
docker run -d -v /root/test:/usr/share/nginx/html nginx:1.19.2
-i : 打开标准输出
-t : 创建一个伪准端
-e : 在容器内设置一个环境变量
docker run -d -e NGINX_NAME=nginx nginx:1.19.2


docker 当中至少有一个应用程序运行在前台


# 停止容器
docker stop [容器名称 | 容器ID]

docker stop nginx_name

 

 

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/dachangtui/p/14063895.html