docker

【docker 笔记】docker 镜像相关整理

2019-05-04  本文已影响3人  58bc06151329

文前说明

作为码农中的一员,需要不断的学习,我工作之余将一些分析总结和学习笔记写成博客与大家一起交流,也希望采用这种方式记录自己的学习之旅。

本文仅供学习交流使用,侵权必删。
不用于商业目的,转载请注明出处。

1. 概述

1.1 最小的镜像

[root@localhost ~]# docker pull hello-world
Using default tag: latest
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
Status: Image is up to date for docker.io/hello-world:latest
[root@localhost ~]# docker images hello-world
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              fce289e99eb9        4 months ago        1.84 kB
FROM scratch
COPY hello /
CMD ["/hello"]
[root@localhost ~]# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

1.2 base 镜像

FROM scratch
ADD centos-7-docker.tar.xz /
CMD ["/bin/bash"]

1.3 镜像的分层结构

镜像分层 镜像分层 2
FROM debian
RUN opt-get install emacs
RUN opt-get install apache2
CMD ["/bin/bash"]

Copy-on-Write

2. 构建镜像

镜像的表示

2.1 镜像的缓存特性

2.2 调试 Dockerfile

2.3 RUN、CMD 和 ENTRYPOINT 区别

3. 镜像的基础操作

操作 说明
images 列出本地镜像。
rmi 删除本地一个或多少镜像。
tag 标记本地镜像,将其归入某一仓库。
build 用于使用 Dockerfile 创建镜像。
history 查看指定镜像的创建历史。
save 将指定镜像保存成 tar 归档文件。
load 导入使用 docker save 命令导出的镜像。
操作 说明
login 登陆到一个 Docker 镜像仓库,如果未指定镜像仓库地址,默认为官方仓库 Docker Hub。
logout 登出一个 Docker 镜像仓库,如果未指定镜像仓库地址,默认为官方仓库 Docker Hub。
pull 从镜像仓库中拉取或者更新指定镜像。
push 将本地的镜像上传到镜像仓库,需要先登陆到镜像仓库。
search 从 Docker Hub 查找镜像。

4. 镜像优化

参考资料

https://blog.csdn.net/runner668/article/details/80785241

上一篇 下一篇

猜你喜欢

热点阅读