容器基础镜像首选-Alpine Linux简介

Alpine Linux简介

Small. Simple. Secure.
Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.
以上为 Alpine Linux 官网的说明,从中可以看出其特点
1.小巧,最小的docker镜像只有5M多。
2.简单,提供APK包管理工具,软件的搜索、安装、删除、升级都非常方便。
3.安全,面向安全的轻量发行版

基于以上特点,非常适合作为容器的基础镜像。

docker 运行

查询 docker search Alpine

NAME DESCRIPTION STARS OFFICIAL AUTOMATED
alpine A minimal Docker image based on Alpine Linux… 9439 [OK]
alpinelinux/docker-cli Simple and lightweight Alpine Linux image wi… 6
alpinelinux/gitlab-runner Alpine Linux gitlab-runner (supports more ar… 4
alpinelinux/alpine-gitlab-ci Build Alpine Linux packages with Gitlab CI 3
alpinelinux/gitlab Alpine Linux based Gitlab image 2

拉取 docker pull alpine

查看 docker images
[root@hecs-393352 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
java-8-git latest 5447e346bca6 24 hours ago 121MB
alpine latest bfe296a52501 9 days ago 5.54MB
node 14-alpine3.15 6dad24e1870b 12 days ago 121MB
ubuntu latest a8780b506fa4 2 weeks ago 77.8MB
gitlab/gitlab-ce latest 98ddb2e28063 6 weeks ago 2.72GB
mysql latest 43fcfca0776d 2 months ago 449MB
centos latest 5d0da3dc9764 14 months ago 231MB
可以看出 alpine只有5.54M,我们同样拉取熟悉的centos和ubuntu,可以看到分别在231M和77.8M。

运行 docker run -it alpine
[root@hecs-393352 ~]# docker run -it alpine
/ #
我们看到已经进入到alpine内部
执行命令 体验一下
/ # ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # cat /etc/os-release
NAME=“Alpine Linux”
ID=alpine
VERSION_ID=3.16.3
PRETTY_NAME=“Alpine Linux v3.16”
HOME_URL=“https://alpinelinux.org/”
BUG_REPORT_URL=“https://gitlab.alpinelinux.org/alpine/aports/-/issues”
/ #
查看操作系统信息

作为docker容器的基础镜像

编写Dockerfile,以alpine作为基础镜像,并按照git客户端 ,做一个新的镜像

编写Dockerfile

编译Dockerfile

[root@hecs-393352 be]# docker build -f ./Dockerfile -t alpine-git .
Sending build context to Docker daemon 338.9MB
Step 1/3 : FROM alpine:latest
—> bfe296a52501
Step 2/3 : RUN apk add git
—> Running in 92c523967a38
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
(1/7) Installing ca-certificates (20220614-r0)
(2/7) Installing brotli-libs (1.0.9-r6)
(3/7) Installing nghttp2-libs (1.47.0-r0)
(4/7) Installing libcurl (7.83.1-r4)
(5/7) Installing expat (2.5.0-r0)
(6/7) Installing pcre2 (10.40-r0)
(7/7) Installing git (2.36.3-r0)
Executing busybox-1.35.0-r17.trigger
Executing ca-certificates-20220614-r0.trigger
OK: 19 MiB in 21 packages
Removing intermediate container 92c523967a38
—> ee157c702ed5
Step 3/3 : RUN git --version
—> Running in 3a04384ba5f2
git version 2.36.3
Removing intermediate container 3a04384ba5f2
—> af07175059d3
Successfully built af07175059d3
Successfully tagged alpine-git:latest

查看一下 已存在镜像alpine-git
[root@hecs-393352 be]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine-git latest af07175059d3 About a minute ago 22.1MB
java-8-git latest 5447e346bca6 29 hours ago 121MB
alpine latest bfe296a52501 9 days ago 5.54MB

运行一下新镜像
docker run -itd alpine-git
4496a5cf1bd0e1e89b8818ccdc89fdc98f1d8c7c80cd059f775a8ec7ce16d098
[root@hecs-393352 be]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4496a5cf1bd0 alpine-git “/bin/sh” 8 seconds ago Up 8 seconds naughty_turing
f460888da36d alpine “/bin/sh” 3 hours ago Up 3 hours adoring_visvesvaraya
48b3fa044c41 ubuntu “/bin/sh” 4 hours ago Up 4 hours musing_lamport
ecfd9b30c9dd alpine “/bin/sh” 4 hours ago Up 4 hours thirsty_blackwell
2235bdc1423f mysql “docker-entrypoint.s…” 2 months ago Up 4 weeks 0.0.0.0:3306->3306/tcp, 33060/tcp mysqlwill

[root@hecs-393352 be]# docker exec -it 4496a5cf1bd0 /bin/sh
/ # git --version
git version 2.36.3
/ #

Alpine Linux 包管理器

alpine使用包管理器名为apk。具体可以使用help 来查看

/ # apk --help
apk-tools 2.12.9, compiled for x86_64.

usage: apk […] COMMAND […]

Package installation and removal:
add Add packages to WORLD and commit changes
del Remove packages from WORLD and commit changes

System maintenance:
fix Fix, reinstall or upgrade packages without modifying WORLD
update Update repository indexes
upgrade Install upgrades available from repositories
cache Manage the local package cache

Querying package information:
info Give detailed information about packages or repositories
list List packages matching a pattern or other criteria
dot Render dependencies as graphviz graphs
policy Show repository policy for packages
search Search for packages by name or description

Repository maintenance:
index Create repository index file from packages
fetch Download packages from global repositories to a local directory
manifest Show checksums of package contents
verify Verify package integrity and signature

Miscellaneous:
audit Audit system for changes
stats Show statistics about repositories and installations
version Compare package versions or perform tests on version strings

This apk has coffee making abilities.
For more information: man 8 apk
/ #

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

祺稷

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值