更新系统软件

更新系统软件yum update -y --exclud=kernel* 参数:--exclud 排除相关软件包 镜像 : 创建容器的模板 容

 

# 更新系统软件
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


-d : 以守护进程的方式运行
-p : 映射固定端口
-P : 映射随机端口
-i : 打开标准输出
-t : 创建一个伪终端
--rm : 当一个容器结束了它的生命周期,就立即删除
--name: 设置一个容器的名称
将容器的名称解析到Docker DNS
-e : 设置一个容器内的环境变量
-v : 挂载一个文件或目录到容器内

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

docker history [仓库URL]/[命名空间名称]/[仓库名称]:[版本号]

docker inspect [仓库URL]/[命名空间名称]/[仓库名称]:[版本号] 或 [IMAGE ID]
参数:
-f : 用golang语言模板语法获取镜像相关信息

docker images 或 docker image ls

[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx v1 c2cdc1ab144d 21 hours ago 133MB
nginx latest bc9a0695f571 6 days ago 133MB
mysql latest dd7265748b5d 10 days ago 545MB
nginx 1.19.2 7e4d58f0e5f3 2 months ago 133MB

列表参数:
REPOSITORY : 仓库名称
TAG: 版本号
IMAGE ID:镜像ID
CREATED : 时间段
SIZE : 镜像体积

参数
-a : 查看所有镜像(包括临时镜像文件)

docker search [参数] [仓库名称]
docker search python

参数 :

-f :过滤
STARS=150
is-official : 是否是官方镜像
--limit : 显示查询条数

docker ps : 查看正在运行的容器
参数:
-a : 查看容器(包括已经停止了的容器)
-q : 只查看容器ID

docker rm [容器名称或ID]
参数:
-f : 强制删除

docker rmi [镜像名字或者ID]
参数:
-f : 强制删除

docker image prune
参数:
-a : 删除所有未被使用的镜像
-f : 强制删除

docker stop [容器名或ID]
docker stop $(docker ps -q)


docker login [参数] [仓库URL]
docker login --username=xxx xxx.com

docker push [仓库URL]/[命名空间]/[仓库名称]:[版本号]

docker tag [原镜像名称 | 镜像ID] [新镜像名称]


xxx.com


大数据部门: nginx
开发部门: nginx
AI技术生态部 : nginx python django

# 将容器保存成镜像
docker commit [参数] [容器名称或ID]
参数:
-a : 指定作者
-m : 简介
-p : 当保存镜像时,容器暂停运行


# 导入、导出镜像

1、export和import
export保存镜像是针对于容器

docker export [容器名或ID] > [压缩包名称]
docker export 3302aab7a252 > nginx.tar

import 针对的是export保存的压缩包
docker import [压缩包名称] [镜像名称]:[版本号]

1、针对export导出的压缩包
2、可以自定义镜像名称


2、save和load
save保存镜像是针对于镜像
docker save [镜像名或ID] > [压缩包名称]

docker save -o [压缩包名称] [镜像名称或ID ...]

1、当使用镜像ID保存镜像,导入时没有镜像名称
2、可以同时保存多个镜像

docker load < [压缩包名称]

1、针对save保存的压缩包
2、不能自定义名称
3、save保存的更完整


# 进入容器

docker attach [容器名或ID]

docker exec [参数] [容器名或ID] [命令]

 

 

# 复制

# 从容器内复制文件到宿主主机
docker cp [容器ID:容器内文件路径] 宿主主机路径

# 从宿主主机复制文件到容器
docker cp 宿主主机路径 [容器ID:容器内文件路径]