基于Alpine镜像定制自己的工具箱
Alpine介绍
Alpine 操作系统是一个面向安全的轻型 Linux 发行版。目前 Docker 官方已开始推荐使用 Alpine 替代之前的 Ubuntu 做为基础镜像环境。这样会带来多个好处。包括镜像下载速度加快,镜像安全性提高,主机之间的切换更方便,占用更少磁盘空间等。
Alpine的特点:
- 小巧:基于Musl libc和busybox,和busybox一样小巧,最小的Docker镜像只有5MB;
- 安全:面向安全的轻量发行版;
- 简单:提供APK包管理工具,软件的搜索、安装、删除、升级都非常方便。
- 适合容器使用:由于小巧、功能完备,非常适合作为容器的基础镜像。
# 拉取镜像
[root@master src]# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
df20fa9351a1: Already exists
Digest: sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
# 查看镜像大小
[root@master ~]# docker images | grep alpine
alpine latest a24bb4013296 4 weeks ago 5.57MB
# 运行镜像
[root@master src]# docker run -it alpine:latest
/ #
Alpine软件包管理
1. 配置软件源
Alpine源配置文件
/ # cat /etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/v3.11/main
http://dl-cdn.alpinelinux.org/alpine/v3.11/community
由于种种原因,官方源在国内很慢,甚至无法连接,我们将其改为国内镜像源
/ # echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories
/ # echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories
/ # cat /etc/apk/repositories
https://mirrors.aliyun.com/alpine/v3.6/main/
https://mirrors.aliyun.com/alpine/v3.6/community/
使用下面的这个可以始终使用最新版的
echo "https://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories
echo "https://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories
2. 软件包管理
alpine 提供了非常好用的apk软件包管理工具,可以方便地安装、删除、更新软件。
查询软件
/ # apk search curl
lua5.2-curl-0.3.5-r2
uwsgi-alarm_curl-2.0.17-r0
py2-curl-7.43.0-r3
libcurl-7.61.1-r2
py3-curl-7.43.0-r3
py-curl-7.43.0-r3
curl-dev-7.61.1-r2
lua5.3-curl-0.3.5-r2
curl-7.61.1-r2
asterisk-curl-14.7.8-r0
php7-curl-7.1.17-r0
curl-dbg-7.61.1-r2
uwsgi-curl_cron-2.0.17-r0
lua5.1-curl-0.3.5-r2
lua-curl-0.3.5-r2
curl-doc-7.61.1-r2
php5-curl-5.6.40-r0
collectd-curl-5.6.2-r1
gst-plugins-bad1-1.10.4-r1
安装软件
/ # apk add curl
fetch https://mirrors.aliyun.com/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch https://mirrors.aliyun.com/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
(1/6) Installing libressl2.5-libcrypto (2.5.5-r2)
(2/6) Installing ca-certificates (20161130-r3)
(3/6) Installing libssh2 (1.8.2-r0)
(4/6) Installing libressl2.5-libssl (2.5.5-r2)
(5/6) Installing libcurl (7.61.1-r2)
(6/6) Installing curl (7.61.1-r2)
Executing busybox-1.31.1-r9.trigger
Executing ca-certificates-20161130-r3.trigger
OK: 9 MiB in 20 packages
安装软件指定版本
apk add packagename=11.0.2-r0
apk add "packagename>1.2.3-r0" # 设置最小版本
安装本地pkg软件包
apk add --allow-untrusted /path/to/foo.apk
如果有依赖包,就一起安装
apk add --allow-untrusted pkg1.apk pkg2.apk
同时安装多个软件
apk add nodejs npm yarn
卸载软件
/ # apk del curl
(1/6) Purging curl (7.61.1-r2)
(2/6) Purging libcurl (7.61.1-r2)
(3/6) Purging ca-certificates (20161130-r3)
Executing ca-certificates-20161130-r3.post-deinstall
(4/6) Purging libressl2.5-libssl (2.5.5-r2)
(5/6) Purging libssh2 (1.8.2-r0)
(6/6) Purging libressl2.5-libcrypto (2.5.5-r2)
Executing busybox-1.31.1-r9.trigger
OK: 6 MiB in 14 packages
apk使用帮助信息
/ # apk --help
apk-tools 2.10.4, compiled for x86_64.
Installing and removing packages:
add Add PACKAGEs to 'world' and install (or upgrade) them, while ensuring that all dependencies are met
del Remove PACKAGEs from 'world' and uninstall them
System maintenance:
fix Repair package or upgrade it without modifying main dependencies
update Update repository indexes from all remote repositories
upgrade Upgrade currently installed packages to match repositories
cache Download missing PACKAGEs to cache and/or delete unneeded files from cache
Querying information about packages:
info Give detailed information about PACKAGEs or repositories
list List packages by PATTERN and other criteria
dot Generate graphviz graphs
policy Show repository policy for packages
Repository maintenance:
index Create repository index file from FILEs
fetch Download PACKAGEs from global repositories to a local directory
verify Verify package integrity and signature
manifest Show checksums of package contents
Use apk <command> --help for command-specific help.
Use apk --help --verbose for a full command listing.
This apk has coffee making abilities.
基于Alpine定制带有curl的镜像
FROM alpine
RUN echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories
RUN echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories
RUN ["apk","update"]
RUN ["apk","add","curl"]
# 默认是没有开启缓存的,所以装完也不用清缓存
alpine linux 安装包报错
WARNING: Ign解决办法
apk add gcc 时候报错
WARNING: Ignoring APKINDEX.167438ca.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.a2e6dac0.tar.gz: No such file or directory
ERROR: unsatisfiable constraints:
gcc (missing):
required by: world[gcc]
解决办法
apk update
基于Alpine镜像定制自己的工具箱的更多相关文章
- 一个带bash,带glibc,中国时区,非root用户可运行crond命令的基于alpine镜像的Dockerfile
这个镜像现在说起来简单, 带bash(增加执行脚本的兼容性,带GLIBC,中国时区,非root用户可运行crond命令-安全) 但让我开始陷入时,真的让我有段时间有点爆了. 比如,将filebeat文 ...
- 基于alpine定制常用命令镜像
FROM alpine RUN apk update RUN apk add curl coreutils 像busybox.alpine镜像date命令都不是完整版的,不能执行加减的操作(date ...
- 支持HTTP2的cURL——基于Alpine的最小化Docker镜像
cURL是我喜欢的开源软件之一.虽然cURL的强大常常被认为是理所当然的,但我真心地认为它值得感谢和尊重.如果我们的工具箱失去了curl,那些需要和网络重度交互的人(我们大多数人都是这样的)将会陷入到 ...
- 基于alpine用dockerfile创建的爬虫Scrapy镜像
一.下载alpine镜像 [root@DockerBrian ~]# docker pull alpine Using default tag: latest Trying to pull repos ...
- 基于alpine用dockerfile创建的tomcat镜像
1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...
- 基于alpine用dockerfile创建的nginx镜像
1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...
- 基于alpine用dockerfile创建的ssh镜像
1.下载alpine镜像 [root@docker43 ~]# docker pull alpine Using default tag: latest Trying to pull reposito ...
- Docker学习笔记:Alpine镜像+Python3安装+http服务器
编写Dockerfile文件使用最新的Alpine镜像并安装Python3环境,如下: 因为python高于3.4则不会默认安装pip,需要手动安装. 试了很多其他办法都没安装上,唯有下载get-pi ...
- sh: /etc/init.d/sshd: not found Docker中的Alpine镜像安装sshd无法启动
问题描述 在Alpine镜像中安装了openssh-server和openssh之后,无法执行ssh localhost.发现未启动服务,开启服务时报以下错误 / # ls /etc/init.d/s ...
随机推荐
- CH341驱动安装
CH341驱动安装 参考文章:https://blog.csdn.net/qq_33194301/article/details/104510078 方法一: 下载驱动包,按提示编译,会出现下面报错 ...
- ApiDay002_01 正则表达式
正则表达式 用于检测.测试字符串规则的表达式. 经常用于检测字符串是否符合特定的规则,在网站上经常用于检测用户输入数据是否符合规范: 检测 用户名 是否为 8~10 数字 英文(大小写) 检测 电话号 ...
- C++指针和结构体基础知识
学习C++首先要回忆起C语言当中的指针和结构体知识,本文作者将通过一段代码来总结指针和结构体基础知识:指针是一个变量,其值为另一个变量的地址,即,内存位置的直接地址.就像其他变量或常量一样,您必须在使 ...
- Modbus转BACnet IP网关
BACnet是楼宇自动化和控制网络数据通信协议的缩写.它是为楼宇自动化网络开发的数据通信协议 根据1999年底互联网上楼宇自动化网络的信息,全球已有数百家国际知名制造商支持BACnet,包括楼宇自 ...
- YII behaviors使用
文件 frontend/libs/FilterTest.php <?php /** * Created by PhpStorm. * Date: 2016/5/27 * Time: 14:16 ...
- 使用Mpvue配合Weui开发面试题题库微信小程序,并且发布到正式环境
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_116 之前的一篇文章详细阐述了微信小程序开发的准备和入门以及环境搭建,这一次我们介绍如何将微信小程序如何上线,同时配合weui美化 ...
- 如何在CDH5上部署Dolphin Scheduler 1.3.1
点击蓝色字关注! 本篇文章大概8440字,阅读时间大约20分钟 本文记录了在CDH5.16.2集群上集成Dolphin Scheduler 1.3.1的详细流程,特别注意一下MySQL数据库的连接串! ...
- (一)esp32开发环境搭建(VSCode+IDF实现单步调试)
保姆级手把手教学视频 https://www.bilibili.com/video/BV1RL411A7CU 前言 因为碰上一个学长,跟他聊了会儿天,推荐我做一点物联网的项目,想来想去,那就用WiFi ...
- 重看Java教学视频时的查漏补缺
数据类型 1.基本数据类型:四类八种. 2.数据范围与字节数不一定相关.如float为4字节表示范围比long的8字节要大. 3.浮点数默认double类型,如要用float,需加F. 4.boole ...
- mongo数据同步的三种方案
(一)直接复制data目录(需要停止源和目标的mongo服务)1.针对目标mongo服务已经存在,并正在运行的(mongo2-->mongo).执行步骤:(1).停止源/目标服务器的mongo服 ...