什么是Alpine Linux?

Alpine Linux是一个由社区开发的基于musl和BusyBox的Linux操作系统,该操作系统以安全为理念,面向x86路由器、防火墙、虚拟专用网、IP电话盒及服务器而设计。

官网:www.alpinelinux.org

维基百科:https://zh.wikipedia.org/wiki/Alpine_Linux

系统特性

1.Alpine使用了自己的包管理系统apk-tools

2.Alpine Linux可以安装为从RAM运行的操作系统。

3.Alpine Linux目前使用的init系统是轻量级的OpenRC,不同于很多发行版包括Debian、Ubuntu、RHEL、Arch Linux和CentOS,Alpine不使用systemd。

安装Alpine

下载镜像并启动,地址 https://www.alpinelinux.org/downloads/

#启动后输入root进入系统,没有密码
Welcome to Alpine Linux 3.16
Kernel 5.15.59-0-lts on an x86_64 (/dev/tty1)
alpine login: root

#登录系统后输入setup-alpine开始安装
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <http://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

alpine:~# setup-alpine

1.设置键盘布局 
us-us
cn-cn
2.设置网络
#设置ip地址
Ip address for eth0? (or 'dhcp', 'none', '?') [10.86.1.129] xxx.xxx.xxx.xxx
#设置子网
Netmask? [255.0.0.0] xxx.xxx.xxx
#设置网关
Gateway? (or 'none') [10.86.1.2] xxx.xxx.xxx
#设置DNS
DNS nameserver(s)? [10.86.1.2] 114.114.114.114
#设置root密码
Changing password for root
New password:
Bad password: too weak
Retype password:
passwd: password for root changed by root
|||||||||||||||||||||||||||||||||||||||||||||||||||| 100%
#设置时区 ,中国选PRC
Which timezone are you in? ('?' for list) [UTC] ?
Africa/      Brazil/      EST          GB           HST          Japan        NZ           Portugal     UTC
America/     CET          EST5EDT      GB-Eire      Hongkong     Kwajalein    NZ-CHAT      ROC          Universal
Antarctica/  CST6CDT      Egypt        GMT          Iceland      Libya        Navajo       ROK          W-SU
Arctic/      Canada/      Eire         GMT+0        Indian/      MET          PRC          Singapore    WET
Asia/        Chile/       Etc/         GMT-0        Iran         MST          PST8PDT      Turkey       Zulu
Atlantic/    Cuba         Europe/      GMT0         Israel       MST7MDT      Pacific/     UCT          posixrules
Australia/   EET          Factory      Greenwich    Jamaica      Mexico/      Poland       US/          right/
Which timezone are you in? ('?' for list) [UTC] PRC
#设置软件源 14为清华源,54为阿里云
Available mirrors:
1) dl-cdn.alpinelinux.org
2) uk.alpinelinux.org
3) mirror.yandex.ru
4) mirrors.gigenet.com
5) mirror1.hs-esslingen.de
6) mirror.leaseweb.com
7) mirror.fit.cvut.cz
8) alpine.mirror.far.fi
9) alpine.mirror.wearetriple.com
10) mirror.clarkson.edu
11) mirror.aarnet.edu.au
12) mirrors.dotsrc.org
13) ftp.halifax.rwth-aachen.de
14) mirrors.tuna.tsinghua.edu.cn
15) mirrors.ustc.edu.cn
16) mirrors.nju.edu.cn
17) mirror.lzu.edu.cn
18) ftp.acc.umu.se
19) mirror.xtom.com.hk
20) mirror.csclub.uwaterloo.ca
21) alpinelinux.mirror.iweb.com
22) pkg.adfinis.com
23) mirror.ps.kz
24) mirror.rise.ph
25) mirror.operationtulip.com
26) mirrors.ircam.fr
27) mirror.math.princeton.edu
28) mirrors.sjtug.sjtu.edu.cn
29) ftp.icm.edu.pl
30) mirror.ungleich.ch
31) mirrors.edge.kernel.org
32) ap.edge.kernel.org
33) eu.edge.kernel.org
34) download.nus.edu.sg
35) alpine.yourlabs.org
36) mirror.pit.teraswitch.com
37) mirror.reenigne.net
38) quantum-mirror.hu
39) tux.rainside.sk
40) alpine.cs.nycu.edu.tw
41) mirror.ihost.md
42) mirror.ette.biz
43) mirror.lagoon.nc
44) alpinelinux.c3sl.ufpr.br
45) foobar.turbo.net.id
46) alpine.ccns.ncku.edu.tw
47) mirror.dst.ca
48) mirror.kumi.systems
49) mirror.sabay.com.kh
50) alpine.northrepo.ca
51) alpine.bardia.tech
52) mirrors.ocf.berkeley.edu
53) mirrors.pardisco.co
54) mirrors.aliyun.com
55) mirror.alwyzon.net
56) mirror1.ku.ac.th
57) mirrors.bfsu.edu.cn
58) ftpmirror2.infania.net
59) repo.iut.ac.ir
60) mirror.fcix.net
61) alpine.sakamoto.pl
62) mirror.2degrees.nz
63) mirror.arvancloud.com
64) mirror.0-1.cloud
65) mirror.kku.ac.th
66) mirror.uepg.br
67) alpine.astra.in.ua
68) mirrors.neusoft.edu.cn
69) ftp.udx.icscoe.jp
70) alpinelinux.mirror.garr.it
71) mirrors.hostico.ro
72) mirror.serverion.com
73) alpinelinux.qontinuum.space
74) alpine.kyberorg.fi

r) Add random from the above list
f) Detect and add fastest mirror from above list
e) Edit /etc/apk/repositories with text editor

Enter mirror number (1-74) or URL to add (or r/f/e/done) [1]

#新建用户名
Setup a user? (enter a lower-case loginname, or 'no') [no]
#设置ssh服务
Which ssh server? ('openssh', 'dropbear' or 'none') [openssh] openssh
#设置root远程登陆
Allow root ssh login? ('?' for help) [prohibit-password] ?
Valid options are:

  yes                root will be able to login with password or ssh key

  no                 root will not be allowed to login with ssh

  prohibit-password  root will be able to login with ssh key but not with
                     password
Allow root ssh login? ('?' for help) [prohibit-password]yes
#安装结束

APK软件包操作

apk
apk-tools 2.12.9, compiled for x86_64.

usage: apk [<OPTIONS>...] COMMAND [<ARGUMENTS>...]

Package installation and removal:
  add        #添加一个软件包
  del        #删除一个软件包

System maintenance:
  fix        #重新安装软件
  update     #更新软件列表
  upgrade    #更新已安装的软件
  cache      #管理本地缓存包

Querying package information:
  info       Give detailed information about packages or repositories
  list       #列出与模块或其他条件匹配的包
  dot        #将依赖项呈现为graphviz图
  policy     Show repository policy for packages
  search     #按名称或描述搜索包

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

#软件源路径 
etc/apk/repositories

/media/cdrom/apks
http://mirrors.aliyun.com/alpine/v3.16/main			#主要软件仓库
http://mirrors.aliyun.com/alpine/v3.16/community	#社区软件仓库
#http://mirrors.aliyun.com/alpine/edge/main			
http://mirrors.aliyun.com/alpine/edge/community
#http://mirrors.aliyun.com/alpine/edge/testing

http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/main
http://mirrors.tuna.tsinghua.edu.cn/alpine/v3.16/community
#http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/main
http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community
#http://mirrors.tuna.tsinghua.edu.cn/alpine/edge/testing

安装Docker

#启动社区软件仓库
在 etc/apk/repositories 取消社区软件仓库的注释

#更新软件列表
apk update

#安装Docker
apk add docker

#设置Docker仓库源
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://0b27f0a81a00f3560fbdc00ddd2f99e0.mirror.swr.myhuaweicloud.com",
    "https://1m20yrx2.mirror.aliyuncs.com",
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}
EOF

#设置Docker 开机自启 
rc-update add docker boot
#alpine:/etc/apk# rc-update add docker boot
# * service docker added to runlevel boot

#启动Docker 守护进程
service docker start
#alpine:/etc/apk# service docker start
# * /var/log/docker.log: creating file
# * /var/log/docker.log: correcting owner
# * Starting Docker Daemon ...

#启动测试进程
docker run --rm alpine ping baidu.com

#安装 docker-compose
apk search docker-compose

#验证docker-compose 是否安装成功
docker-compose version
#localhost:~# docker-compose version
#docker-compose version 1.29.2, build unknown
#docker-py version: 5.0.3
#CPython version: 3.10.5
#OpenSSL version: OpenSSL 1.1.1q  5 Jul 2022