Docker-基本操作

镜像操作

镜像操作基本命令:

[root@KVM02 docker]# docker image --help

Usage:	docker image COMMAND

Manage images

Commands:
  build       Build an image from a Dockerfile   
              #通过Dockerfile文件构建镜像
  history     Show the history of an image       
              #显示镜像的历史信息
  import      Import the contents from a tarball to create a filesystem image
              #从一个保存的tar文件导入一个镜像
  inspect     Display detailed information on one or more images
  			  #查看镜像的详细信息
  load        Load an image from a tar archive or STDIN
  			  #加载一个镜像
  ls          List images
              #镜像列表
  prune       Remove unused images
              #移除没有使用的镜像
  pull        Pull an image or a repository from a registry
              #从仓库中下载一个镜像
  push        Push an image or a repository to a registry
              #把镜像上传到仓库
  rm          Remove one or more images
              #移除一个或多个镜像
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
              #保存镜像
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
              #给镜像打标签
1、 搜索官方仓库镜像
[root@KVM02 docker]# docker search nginx
NAME (镜像名字)             DESCRIPTION (描述信息)                          STARS (星级)    OFFICIAL          AUTOMATED
nginx                       Official build of Nginx.                        13923            [OK]                
jwilder/nginx-proxy         Automated Nginx reverse proxy for docker con…   1900                                    [OK]
richarvey/nginx-php-fpm     Container running Nginx + PHP-FPM capable of…   791                                     [OK]
2、 拉取镜像
[root@KVM02 docker]# docker pull busybox   
#拉取得为最新版
[root@KVM02 docker]# docker pull nginx:1.14-alpine
#拉取指定版本
[root@KVM02 docker]# docker pull Ubuntu
3、查看当前主机镜像列表
[root@KVM02 docker]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              d70eaf7277ea        4 days ago          72.9MB
busybox             latest              f0b02e9d092d        2 weeks ago         1.23MB
4、登录
方法一:
[root@KVM02 docker]# docker login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: xxvv01
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
#登陆成功

方法二:
[root@KVM02 docker]# docker login -u  **  -p **
-u  用户名
-p  密码
5、登出
[root@KVM02 docker]# docker logout 
Removing login credentials for https://index.docker.io/v1/
创建仓库

点击Create Repository按钮
在这里插入图片描述
编译仓库名–选择私有还是公有–点击Create创建
在这里插入图片描述
点击这个按钮查看
在这里插入图片描述

6、上传镜像–前提:打标签
[root@KVM02 docker]# docker tag --help
Usage:	docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
例:
[root@KVM02 docker]# docker tag busybox:latest xxvv01/xx:busybox.v1
#打标签
[root@KVM02 docker]# docker push xxvv01/xx:busybox.v1
#上传镜像
The push refers to repository [docker.io/xxvv01/dockertest/busybox]
The push refers to repository [docker.io/xxvv01/xx]
d2421964bad1: Pushed 
busybox.v1: digest: sha256:c9249fdf56138f0d929e2080ae98ee9cb2946f71498fc1484288e6a935b5e5bc size: 527
7、导出镜像
[root@KVM02 docker]# docker image save --help
格式:	docker image save [OPTIONS] IMAGE [IMAGE...]
  -o,--output string   Write to a file, instead of STDOUT

方法一:重定向
[root@KVM02 ~]# docker image save busybox:latest > busybox1.tar
方法二:-o
[root@KVM02 ~]# docker image save busybox:latest -o busybox2.tar 

注:两者权限不同
[root@KVM02 ~]# ll -h
-rw-r--r--. 1 root root 1.4M 10月 28 22:47 busybox1.tar
-rw-------. 1 root root 1.4M 10月 28 22:48 busybox2.tar
8、删除镜像
方法一:
[root@KVM02 ~]# docker image rm busybox:latest 
Untagged: busybox:latest
Untagged: busybox@sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d
方法二:
[root@KVM02 ~]# docker rmi busybox:latest 
9、加载镜像
[root@KVM02 ~]# docker image load -i busybox1.tar 
Loaded image: busybox:latest
10、导入镜像
[root@KVM02 ~]# docker image import --help
格式:	docker image import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Options:
  -c, --change list       Apply Dockerfile instruction to the created image
  -m, --message string    Set commit message for imported image
      --platform string   Set platform if server is multi-platform capable

例:
[root@KVM02 ~]# docker image import busybox1.tar (镜像没有名称)
注:删除可以用ID号删除
11、查看镜像的详细信息
[root@KVM02 ~]# docker image inspect ubuntu
镜像的保存对比

docker save与docker export的区别:
1、save/load ; export /import成对使用
2、docker save保存的是镜像,docker export保存的是容器。

[root@KVM02 ~]# docker save --help
Usage:	docker save [OPTIONS] IMAGE [IMAGE...]
Options:
  -o, --output string   Write to a file, instead of STDOUT

[root@KVM02 ~]# docker save  busybox:latest -o busybox.tar

[root@KVM02 ~]# docker import  --help
Usage:	docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Options:
  -c, --change list       Apply Dockerfile instruction to the created image
  -m, --message string    Set commit message for imported image
      --platform string   Set platform if server is multi-platform capable

[root@KVM02 ~]# docker export busybox -o busybox2.tar

将busybox,busybox2下载到windows桌面查看其区别:
在这里插入图片描述
busybox只有一层镜像
在这里插入图片描述
busybox2储存的是linux文件系统

镜像的加载对比

load与import的区别
**
1、docker load用来载入镜像包,docker import用来载入容器包,但两者都会恢复镜像。
2、docker load不能对载入的镜像重命名,而docker import 可以为镜像指定新的名称。
**
用load加载镜像

[root@KVM02 ~]# docker load  --help
Usage:	docker load [OPTIONS]
Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

[root@KVM02 ~]# docker image load -i busybox1.tar 
Loaded image: busybox:latest
[root@KVM02 ~]# docker image ls busybox
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              f0b02e9d092d        2 weeks ago         1.23MB

用import加载镜像

[root@KVM02 ~]# docker import --help
Usage:	docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
Options:
  -c, --change list       Apply Dockerfile instruction to the created image
  -m, --message string    Set commit message for imported image
      --platform string   Set platform if server is multi-platform capable

方法一:直接加载,镜像没有标签
[root@KVM02 ~]# docker image import busybox2.tar 
sha256:5789f0eb51eadb68e873b42e21450cb39fdcdbf9783d03dee0f2859d21c1e532
[root@KVM02 ~]# docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              5789f0eb51ea        9 seconds ago       1.23MB
给镜像打标签
[root@KVM02 ~]# docker tag 5789f0eb51ea busybox:latest 
[root@KVM02 ~]# docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
busybox             latest              5789f0eb51ea        About a minute ago   1.23MB

方法二:加载镜像并且给镜像打标签
[root@KVM02 ~]# cat busybox2.tar | docker import -  busybox:latest
sha256:976accbdf961003b3e49638623d60f4cc0341e79ff1ea91795ecba2908407cd9
[root@KVM02 ~]# docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              976accbdf961        22 seconds ago      1.23MB

容器操作

1、创建容器
[root@KVM02 ~]# docker create busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
9758c28807f2: Pull complete 
Digest: sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d
Status: Downloaded newer image for busybox:latest
2、查看容器
方法一:
[root@KVM02 ~]# docker ps 
#查看正在运行中的容器
[root@KVM02 ~]# docker ps -a
#查看全部容器
方法二:
[root@KVM02 ~]# docker container ls
#查看运行中的容器
3、启动容器
方法一:
[root@KVM02 ~]# docker start busybox
方法二:
[root@KVM02 ~]# docker run 
-t :打开一个终端,像使用交换机一样使用容器
-i: 交互式访问
--name:容器名字
--network:指定网络
--rm:容器一停,自动删除
-d:剥离与当前终端的关系;否则会一直占据着终端
-p:端口映射,将容器内服务的端口映射在宿主机的指定端口

例:
[root@KVM02 ~]# docker run -d  nginx:1.14-alpine 

如何让-it退出时,保持容器运行:ctrl+P,Q
[root@KVM02 ~]# docker run -it nginx:1.14-alpine  /bin/sh
/ # [root@KVM02 ~]#

--name
[root@KVM02 ~]# docker run -d --name nginx1 nginx:1.14-alpine
#给容器命名
--rm
[root@KVM02 ~]# docker run --rm -it nginx:1.14-alpine /bin/sh
#退出即删除
4、停止运行中的容器
方法一:
[root@KVM02 ~]# docker stop nginx1
#停止容器
方法二:
[root@KVM02 ~]# docker kill nginx1
-s:指定信号,和kill 用法一样;-9 强制停止容器
5、激活关闭的容器
[root@KVM02 ~]# docker start  nginx1 
-a:附加到当前终端
-i:交互式
6、查看容器的详细信息
[root@KVM02 ~]# docker inspect nginx1
7、删除容器
[root@KVM02 ~]# docker rm nginx1 
#删除容器
[root@KVM02 ~]# docker ps -aq
f421cbd6ae40
#根据ID号查看若有容器

[root@KVM02 ~]# docker rm -f `docker ps -aq`
#删除所有容器,默认只能删未运行的容器
-f 强制删除
8、对运行的容器执行指定的命令
[root@KVM02 ~]# docker exec -it nginx1 /bin/sh
-d:在后台运行命令
-e:设置环境变量
-i:交互式
-t:打开一个终端
-u:用户名或UID
9、查询容器内部日志
[root@KVM02 ~]# docker exec nginx1 ip a
#查看容器的IP地址
[root@KVM02 ~]# curl 172.17.0.3
#访问容器
[root@KVM02 ~]# docker logs nginx1 
172.17.0.1 - - [29/Oct/2020:14:34:32 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
#查看日志
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 内容概要 《计算机试卷1》是一份综合性的计算机基础和应用测试卷,涵盖了计算机硬件、软件、操作系统、网络、多媒体技术等多个领域的知识点。试卷包括单选题和操作应用两大类,单选题部分测试学生对计算机基础知识的掌握,操作应用部分则评估学生对计算机应用软件的实际操作能力。 ### 适用人群 本试卷适用于: - 计算机专业或信息技术相关专业的学生,用于课程学习或考试复习。 - 准备计算机等级考试或职业资格认证的人士,作为实战演练材料。 - 对计算机操作有兴趣的自学者,用于提升个人计算机应用技能。 - 计算机基础教育工作者,作为教学资源或出题参考。 ### 使用场景及目标 1. **学习评估**:作为学校或教育机构对学生计算机基础知识和应用技能的评估工具。 2. **自学测试**:供个人自学者检验自己对计算机知识的掌握程度和操作熟练度。 3. **职业发展**:帮助职场人士通过实际操作练习,提升计算机应用能力,增强工作竞争力。 4. **教学资源**:教师可以用于课堂教学,作为教学内容的补充或学生的课后练习。 5. **竞赛准备**:适合准备计算机相关竞赛的学生,作为强化训练和技能检测的材料。 试卷的目标是通过系统性的题目设计,帮助学生全面复习和巩固计算机基础知识,同时通过实际操作题目,提高学生解决实际问题的能力。通过本试卷的学习与练习,学生将能够更加深入地理解计算机的工作原理,掌握常用软件的使用方法,为未来的学术或职业生涯打下坚实的基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值