
较旧版本的Docker被称为docker或docker-engine。
curl -fsSL https://get.docker.com | bash --mirror Aliyun
Aliyun Docker CE镜像, 清华大学Docker CE 软件仓库
Ubuntu(使用 apt-get 进行安装)
x# step 2: 信任 Docker 的 GPG 公钥sudo install -m 0755 -d /etc/apt/keyringscurl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgsudo chmod a+r /etc/apt/keyrings/docker.gpg# Step 3: 写入软件源信息echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \sudo tee /etc/apt/sources.list.d/docker.list > /dev/null# Step 4: 安装Dockersudo apt-get updatesudo apt-get install docker-ce# 安装指定版本的Docker-CE:# Step 1: 查找Docker-CE的版本:# apt-cache madison docker-ce# docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages# docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages# Step 2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.1~ce-0~ubuntu-xenial)# sudo apt-get -y install docker-ce=[VERSION]
Debian
xxxxxxxxxx# Step 3: 写入软件源信息echo \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian \"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullecho \"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \tee /etc/apt/sources.list.d/docker.list > /dev/null
CentOS (使用 yum 进行安装)
xxxxxxxxxx# step 1: 安装必要的一些系统工具sudo yum install -y yum-utils# Step 2: 添加软件源信息yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# 或配置在线repo源cat > /etc/yum.repos.d/docker-ce.repo << EOF[docker-ce-stable]name=Docker CE Stable - \$basearchbaseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/\$releasever/\$basearch/stableenabled=1gpgcheck=1gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpgEOF# Step 3: 安装Dockersudo yum install -y docker-ce# 注意:# 官方软件源默认启用了最新的软件,您可以通过编辑软件源的方式获取各个版本的软件包。例如官方并没有将测试版本的软件源置为可用,您可以通过以下方式开启。同理可以开启各种测试版本等。# vim /etc/yum.repos.d/docker-ce.repo# 将[docker-ce-test]下方的enabled=0修改为enabled=1## 安装指定版本的Docker-CE:# Step 1: 查找Docker-CE的版本:# yum list docker-ce.x86_64 --showduplicates | sort -r# Loading mirror speeds from cached hostfile# Loaded plugins: branch, fastestmirror, langpacks# docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-ce-stable# docker-ce.x86_64 17.03.1.ce-1.el7.centos @docker-ce-stable# docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-ce-stable# Available Packages# Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)# sudo yum -y install docker-ce-[VERSION]
安装校验
xxxxxxxxxx#docker版本docker version#启动Docker服务systemctl enable dockersystemctl restart dockersystemctl status docker#查看Docker是否正常安装并运行docker system infodocker info
xxxxxxxxxxUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]docker run -it ubuntu:12.04 /bin/bashdocker run -it --rm ubuntu:12.04 /bin/bash-i, --interactive=false Keep STDIN open even if not attached-t, --tty=false Allocate a pseudo-TTY--rm Automatically remove the container when it exits#Docker默认存储位置 /var/lib/dockerdocker info | grep "Docker Root Dir"
xxxxxxxxxxdocker ps -a-a, --all=false Show all containers (default shows just running)-f, --filter filter Filter output based on conditions providede.g., -f "status=exited", -f "status=running"--format string Pretty-print containers using a Go templatee.g., --format "{{.ID}} {{.Names}} {{.Status}} {{.Image}} {{.CreatedAt}}"-l, --latest=false Show the latest created container, include non-running--no-trunc Don't truncate output
xxxxxxxxxxdocker run -i -t --name ubuntu12.04 ubuntu:12.04 /bin/bash--name string Assign a name to the container
xxxxxxxxxxdocker start ubuntu12.04-i, --interactive=false Attach container's STDIN
xxxxxxxxxxdocker attach ubuntu12.04#如果退出容器的shell,容器也随之停止运行
不会进入容器
xxxxxxxxxxdocker run --name ubuntu12.041 -d ubuntu:12.04 /bin/bash-d, --detach Run container in background and print container ID
xxxxxxxxxxdocker logs ubuntu12.041
xxxxxxxxxxdocker top ubuntu12.041
xxxxxxxxxxdocker exec -d ubuntu12.041 touch /root/1.txt-d, --detach Detached mode: run command in the background#创建TTY并捕捉STDINdocker exec -it ubuntu12.041 /bin/bash-i, --interactive Keep STDIN open even if not attached-t, --tty Allocate a pseudo-TTY
xxxxxxxxxxdocker stop ubuntu12.041
xxxxxxxxxxdocker inspect ubuntu12.041
需要先stop或kill
xxxxxxxxxxdocker rm id
xxxxxxxxxx#从容器里面拷文件到宿主机docker cp b76a6e929470:/home/nacos/conf/ /Users/king/Desktop/docker cp 容器ID:要拷贝的文件在容器中的位置 要拷贝到本地宿主机的位置#从宿主机拷文件到容器里面docker cp 要拷贝的文件路径 容器ID:要拷贝到容器里面对应的路径docker cp /Users/king/Desktop/a.txt b76a6e929470:/home/nacos/conf/
Docker国内可用镜像源仓库地址
https://www.jb51.net/server/336073lax.htm
xxxxxxxxxxvi /etc/docker/daemon.json{"builder": {"gc": {"defaultKeepStorage": "20GB","enabled": true}},"experimental": false,"registry-mirrors": ["https://docker.hpcloud.cloud","https://docker.m.daocloud.io","https://docker.unsee.tech","https://docker.1panel.live","http://mirrors.ustc.edu.cn","https://docker.chenby.cn","http://mirror.azure.cn","https://dockerpull.org","https://dockerhub.icu","https://hub.rat.dev","https://proxy.1panel.live","https://docker.1panel.top","https://docker.m.daocloud.io","https://docker.1ms.run","https://docker.ketches.cn"]}systemctl restart docker
xxxxxxxxxxdocker imagesdocker image lsdocker images --format "{{.Repository}}:{{.Tag}}"
xxxxxxxxxxdocker pull ubuntu:12.04docker pull ubuntu:latest
xxxxxxxxxxdocker search ubuntuNAME DESCRIPTION STARS OFFICIAL AUTOMATEDubuntu Ubuntu is a Debian-based Linux operating s... 5859 [OK]如果search出来的镜像,不是自己想要的版本,可通过在docker hub上搜索好版本TAG地址如下:https://hub.docker.com/[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEcentos 8.3.2011 300e315adb2f 4 months ago 209MBcentos 7.9.2009 8652b9f0cb4c 5 months ago 204MBcentos 8.2.2004 831691599b88 10 months ago 215MBcentos 7.6.1810 f1cb7c7d58b7 2 years ago 202MB
xxxxxxxxxxdocker commit id ubuntu/xx
xxxxxxxxxx# 构建,tag格式:仓库名/镜像名:标签,不指定标签则为latest,可以指定多个-tdocker build -t "apache:latest" -t "apache:7.6" .-t, --tag list Name and optionally a tag in the 'name:tag' format
xxxxxxxxxxdocker images-a, --all=false Show all images (default hides intermediate images)-q, --quiet=false Only show numeric IDs#查看镜像构建的每一层docker history id--no-trunc=true Don't truncate output 不要截断输出,显示完整的命令-q, --quiet=false Only show numeric IDs
xxxxxxxxxxdocker run -d -p 80 --name ubuntu12.042 ubuntu:12.04 /bin/bash-P, --publish-all=false Publish all exposed ports to random ports-p, --publish=[] Publish a container's port(s) to the hostip:hostPort:containerPort (映射指定地址的指定端口)指定映射使用一个特定地址,比如 localhost 地址 127.0.0.1#查看docker网络端口在宿主机中映射的端口,返回宿主机中映射的端口docker port id 800.0.0.0:49154
xxxxxxxxxx#!/bin/bash#set -xREPOSITORY=harbor.mydomain.com/library/IMAGE=simple_warTAG=0.1############################################ builddocker build -t "${IMAGE}:${TAG}" .# tagdocker tag ${IMAGE}:${TAG} ${REPOSITORY}${IMAGE}:${TAG}# login, 在 ~/.docker/config.json# 查看用户名密码: sed -n 's/.*"auth": "\(.*\)"/\1/p' ~/.docker/config.json | base64 -ddocker login -u admin -p Harbor12345 harbor.mydomain.com# push,需要登录docker push ${REPOSITORY}${IMAGE}:${TAG}# rmidocker rmi ${IMAGE}:${TAG}echo ${REPOSITORY}${IMAGE}:${TAG}
xxxxxxxxxxdocker rmi name/id#删除所有镜像docker rmi $(docker images -q)#删除所有未打 tag 的镜像docker rmi $(docker images | awk '/^<none>/ { print $3 }')
xxxxxxxxxxdocker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart always --name myregistry registry:2.8.3registry_server=192.168.1.10:5000registry_server=10.0.4.10:5000# 浏览器访问http://${registry_server}/v2/,出现一对{}说明registry运行正常。curl http://${registry_server}/v2/# 配置insecure-registriescat > /etc/docker/daemon.json << EOF{"insecure-registries": ["${registry_server}"]}EOFsudo systemctl daemon-reloadsudo systemctl restart dockerdocker tag alpine:3.12.7 ${registry_server}/alpine:3.12.7# 推送docker push ${registry_server}/alpine:3.12.7# 浏览器访问http://${registry_server}/v2/_catalogcurl http://${registry_server}/v2/_catalog# 拉取docker pull ${registry_server}/alpine:3.12.7
xxxxxxxxxx# 使用id会丢失镜像repository和tag信息,请使用repository:tag# docker save <id> > /root/ubuntu12.04.imgdocker save repository:tag -o /root/ubuntu12.04.imggzip -9 ubuntu12.04.img# 只打印导出语句docker images --format "{{.Repository}} {{.Tag}}" | awk '{print "docker save "$1":"$2" -o "$1$2".img; gzip -9 "$1$2".img"}'# 导出所有镜像docker images --format "{{.Repository}} {{.Tag}}" | while read linedoimage=$(echo "$line" | awk '{print $1}')tag=$(echo "$line" | awk '{print $2}')set -xdocker save "$image":"$tag" -o "$image$tag".imggzip -9 "$image$tag".imgset +xdone# 导入镜像docker load -i ubuntu12.04.imgdocker load -i ubuntu12.04.img.gz# 若TAG为<none>,为将镜像id打上TAGdocker tag <id> ubuntu:12.04# 导入所有镜像for i in $(ls *.img.gz);do echo $i;docker load -i $i; done
xxxxxxxxxxdocker system df
TYPE 列出了 Docker 使用磁盘的 4 种类型:
| 类型 | 说明 |
|---|---|
| Images | 所有镜像占用的空间,包括拉取下来的镜像,和本地构建的。 |
| Containers | 运行的容器占用的空间,表示每个容器的读写层的空间。 |
| Local Volumes | 容器挂载本地数据卷的空间。 |
| Build Cache | 镜像构建过程中产生的缓存空间(只有在使用 BuildKit 时才有,Docker 18.09 以后可用)。 |
xxxxxxxxxxdocker builder prune# 清理10天之前的缓存docker builder prune --filter 'until=240h'# 清理磁盘,删除所有关闭的容器、网络、dangling镜像(即无tag的镜像)、无用的数据卷docker system prune# 清理得更加彻底,删掉未使用Docker镜像docker system prune -a
xxxxxxxxxxvi /usr/lib/systemd/system/docker.serviceExecStart=/usr/bin/dockerd --registry-mirror=https://xp0fxaih.mirror.aliyuncs.comsystemctl daemon-reloadsystemctl restart dockerps aux | grep docker
xxxxxxxxxxdocker run -i -t --name DataTest -v /container_data:/data ubuntu:12.04 /bin/bash-v, --volume list Bind mount a volume (default [])#/host_data:/docker_data#将:前面的(宿主机的/container_dat)目录挂载到:后面的(容器的/data)目录#如果/container_data目录不存在,Docker会自动创建该目录。#查看容器详情,可以看到:docker inspect DataTest"Mounts": [{"Source": "/container_data","Destination": "/data","Mode": "","RW": true,"Propagation": "rprivate"}],
如果容器之间需要共享一些持续更新的数据,最简单的方式就是是用户数据卷容器,数据卷容器就是一种普通容器,专门提供数据卷供其它容器挂载使用。
创建数据卷容器,就是一个普通容器,无需启动
xxxxxxxxxxdocker run -i -t --name DataVolumeTest -v /container_data:/data ubuntu:12.04docker inspect DataVolumeTest"Mounts": [{"Source": "/container_data","Destination": "/data","Mode": "","RW": true,"Propagation": "rprivate"}],
创建db1和db2两个容器,并使用--volumes-from挂载DataVolumeTest容器中的数据卷 注意:使用--volumes-from参数所挂载数据卷的容器自身并不需要保持在运行状态
xxxxxxxxxxdocker run -i -t --name db1 --volumes-from DataVolumeTest ubuntu:12.04 /bin/bashdocker run -i -t --name db2 --volumes-from DataVolumeTest ubuntu:12.04 /bin/bash--volumes-from list Mount volumes from the specified container(s) (default [])docker inspect db1#可以看到和DataVolumeTest容器挂载的信息是一样的"Mounts": [{"Source": "/container_data","Destination": "/data","Mode": "","RW": true,"Propagation": "rprivate"}],
xxxxxxxxxx# docker run --helpUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]-d, --detach=false 指定容器运行于前台还是后台,默认为false-i, --interactive=false 打开STDIN,用于控制台交互-t, --tty=false 分配tty设备,该可以支持终端登录,默认为false-u, --user="" 指定容器的用户-a, --attach=[] 登录容器(必须是以docker run -d启动的容器)-w, --workdir="" 指定容器的工作目录-c, --cpu-shares=0 设置容器CPU权重,在CPU共享场景使用-e, --env=[] 指定环境变量,容器中可以使用该环境变量-m, --memory="" 指定容器的内存上限-P, --publish-all=false 指定容器暴露的端口-p, --publish=[] 指定容器暴露的端口-h, --hostname="" 指定容器的主机名-v, --volume=[] 给容器挂载存储卷,挂载到容器的某个目录--volumes-from=[] 给容器挂载其他容器上的卷,挂载到容器的某个目录--cap-add=[] 添加权限,权限清单详见:http://linux.die.net/man/7/capabilities--cap-drop=[] 删除权限,权限清单详见:http://linux.die.net/man/7/capabilities--cidfile="" 运行容器后,在指定文件中写入容器PID值,一种典型的监控系统用法--cpuset="" 设置容器可以使用哪些CPU,此参数可以用来容器独占CPU--device=[] 添加主机设备给容器,相当于设备直通--dns=[] 指定容器的dns服务器--dns-search=[] 指定容器的dns搜索域名,写入到容器的/etc/resolv.conf文件--entrypoint="" 覆盖image的入口点--env-file=[] 指定环境变量文件,文件格式为每行一个环境变量--expose=[] 指定容器暴露的端口,即修改镜像的暴露端口--link=[] 指定容器间的关联,使用其他容器的IP、env等信息--lxc-conf=[] 指定容器的配置文件,只有在指定--exec-driver=lxc时使用--name="" 指定容器名字,后续可以通过名字进行容器管理,links特性需要使用名字--net="bridge" 容器网络设置:bridge 使用docker daemon指定的网桥host //容器使用主机的网络container:NAME_or_ID >//使用其他容器的网路,共享IP和PORT等网络资源none 容器使用自己的网络(类似--net=bridge),但是不进行配置--privileged=false 指定容器是否为特权容器,特权容器拥有所有的capabilities--restart="no" 指定容器停止后的重启策略:no:容器退出时不重启on-failure:容器故障退出(返回值非零)时重启always:容器退出时总是重启--rm=false 指定容器停止后自动删除容器(不支持以docker run -d启动的容器)--sig-proxy=true 设置由代理接受并处理信号,但是SIGCHLD、SIGSTOP和SIGKILL不能被代理
在Docker容器创建好之后,可能会发现容器时间跟宿主机时间不一致,这就需要同步它们的时间,让容器时间跟宿主机时间保持一致。如下:
xxxxxxxxxx# 宿主机时间[root@slave-1 ~]# dateFri May 12 11:20:30 CST 2017# 容器时间[root@slave-1 ~]# docker exec -ti 87986863838b /bin/bashroot@87986863838b:/# dateFri May 12 03:20:33 UTC 2017
发现两者之间的时间相差了八个小时! 宿主机采用了CST时区,CST指(China Shanghai Time,东八区时间) 容器采用了UTC时区,UTC指(Coordinated Universal Time,标准时间)
统一两者的时区有下面几种方法 1)共享主机的localtime 创建容器的时候指定启动参数,挂载localtime文件到容器内,保证两者所采用的时区是一致的。
xxxxxxxxxx# docker run -ti -d --name my-nginx -v /etc/localtime:/etc/localtime:ro docker.io/nginx /bin/bash
2)复制主机的localtime
xxxxxxxxxx[root@slave-1 ~]# docker cp /etc/localtime 87986863838b:/etc/然后再登陆容器,查看时间,发现已经跟宿主机时间同步了[root@slave-1 ~]# docker exec -ti 87986863838b /bin/bashroot@87986863838b:/# dateFri May 12 11:26:19 CST 2017
3)创建dockerfile文件的时候,自定义该镜像的时间格式及时区。在dockerfile文件里添加下面内容:
xxxxxxxxxxFROM tomcat#设置时区RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
保存后,利用docker build命令生成镜像使用即可,使用dockerfile创建的镜像的容器改变了容器的时区,这样不仅保证了容器时间与宿主机时间一致(假如宿主机也是CST),并且像上面使用tomcat作为父镜像的话,JVM的时区也是CST,这样tomcat的日志信息的时间也是和宿主机一致的,像上面那两种方式只是保证了宿主机时间与容器时间一致,JVM的时区并没有改变,tomcat日志的打印时间依旧是UTC。
长话短说:现在Docker改为基于YY.MM的版本(像Ubuntu),用户可以选择Stable(发布较慢)或者Edge(发布较快)版本。
YY.MM
使用基于月份的发行版本,17.03 的第一版就指向17.03.0,如果有bug/安全修复需要发布,那么将会指向17.03.1等等。tracker server ip can't be 127.0.0.1 也不能是localhost 方法: 指定 -h hostname docker run -h zt_server -it zt:v5
COPY COPY指令和ADD指令的唯一区别在于是否支持从远程URL获取资源。COPY指令只能从执行docker build所在的主机上读取资源并复制到镜像中。而ADD指令还支持通过URL从远程服务器读取资源并复制到镜像中。 满足同等功能的情况下,推荐使用COPY指令。ADD指令更擅长读取本地tar文件并解压缩。
COPY 目录
xxxxxxxxxx#没有把static目录拷贝进来COPY static /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/#加上镜像内的static目录,会自动创建static目录COPY static /usr/local/tomcat/webapps/datafusion/WEB-INF/classes/static
CMD 支持三种格式
xxxxxxxxxxCMD ["executable","param1","param2"] 使用 exec 执行,推荐方式;CMD command param1 param2 在 /bin/sh 中执行,提供给需要交互的应用;CMD ["param1","param2"] 提供给 ENTRYPOINT 的默认参数;
ENTRYPOINT 两种格式:
xxxxxxxxxxENTRYPOINT ["executable", "param1", "param2"]ENTRYPOINT command param1 param2(shell中执行)。
配置容器启动后执行的命令,并且不可被 docker run 提供的参数覆盖。 每个 Dockerfile 中只能有一个 ENTRYPOINT,当指定多个时,只有最后一个起效。
示例appach ENTRYPOINT和CMD配合使用
xxxxxxxxxxENTRYPOINT ["/usr/sbin/httpd"]CMD ["-D", "FOREGROUND"]
带有stretch、buster或jessie标签的镜像是不同Debian发行版的代号。 Debian 11 (bullseye) — 当前的稳定(stable)版 Debian 10(buster) — 当前的旧的稳定(oldstable)版 Debian 9(stretch) — 更旧的稳定(oldoldstable)版,现有长期支持 Debian 8(jessie) — 已存档版本,现有扩展长期支持 Debian 7(wheezy) — 被淘汰的稳定版 Debian 6.0(squeeze) — 被淘汰的稳定版 Debian GNU/Linux 5.0(lenny) — 被淘汰的稳定版 Debian GNU/Linux 4.0(etch) — 被淘汰的稳定版 Debian GNU/Linux 3.1(sarge) — 被淘汰的稳定版 Debian GNU/Linux 3.0(woody) — 被淘汰的稳定版 Debian GNU/Linux 2.2(potato) — 被淘汰的稳定版 Debian GNU/Linux 2.1(slink) — 被淘汰的稳定版 Debian GNU/Linux 2.0(hamm) — 被淘汰的稳定版
在撰写本文时,稳定的Debian发行版是10.4,它的代号是“buster”。 “stretch”是所有版本9变种的代号,“jessie”是所有版本8变种的代号。
正在开发的未来版本是“bullseye ”和“bookworm”,但还不稳定。你可能会在DockerHub上的镜像版本列表中看到这些标签。
如果您的代码与Debian操作系统的特定版本兼容,请选择其中一个镜像。在开始一个新项目时,你很少需要使用旧版本的Debian。
slim
slim的镜像是完整镜像的配对版本。这个镜像通常只安装运行特定工具所需的最小包。以python为例,就是运行python的最小包,node.js同理。
通过省去较少使用的工具,镜像会更小。如果有空间限制且不需要完整版本,请使用此镜像。
但是,在使用这个镜像时,一定要进行彻底的测试!如果您遇到无法解释的错误,请尝试切换到完整的镜像,看看是否能够解决问题。
alpine
alipine镜像基于alpine linux项目,这是一个专门为容器内部使用而构建的操作系统。在很长一段时间里,这些是最受欢迎的镜像变体,因为它们的尺寸很小。
然而,一些团队正在弃用alpine镜像,因为这些镜像可能会导致难以调试的兼容性问题。具体来说,如果使用python镜像,一些 wheels将被构建成与Debian兼容,并且需要重新编译,才能与基于apline的镜像一起工作。
使用alpine镜像的主要原因是使你得到的镜像尽可能小。基础镜像将小于5MB。python基础镜像(将python添加到基础alpine镜像)目前是78.9MB。这仍然很小。
如果考虑到空间问题,强烈推荐使用此镜像。
它的缺点是不包含一些你可能会需要的包。主要是,它使用了一个更小的musl lib代替glibc。如果您的应用程序有特定的libc需求,您可能会遇到问题。
如果你发现Alpine镜像缺少你需要的东西,你可以直接在Dockerfile中安装它,这样能确保镜像只包含你需要的内容。需要注意,如果您正在安装外部包,您的Dockerfile将会更改。主要的区别是,您将使用apk而不是apt-get来安装包。
对alpine镜像的使用有很多担心之处,所以你需要充分了解它。需要充分阅读文档并研究。 同样,如果您在构建Dockerfile时遇到了无法解释的问题,请尝试切换到完整的镜像,看看是否能解决问题。
windowsservercore
我很少使用windows,我现在坚定地站在Mac / Linux阵营,但如果你的应用程序只运行在windows或windows Server上,这就是为你准备的镜像。
综述 如何选择镜像
以下是我使用的通用准则:
关于版本的说明
不要在生产系统Dockerfile中使用<image>:latest。这样做将总是获取最新的镜像,并且应用程序的依赖项可能与未来的版本不兼容。
当开始一个新项目时,我通常会从最近标记的版本开始,进行彻底的测试,然后根据需要升级,在投入生产之前进行彻底的测试。