alpine linux操作系统介绍及使用

 阅读大约需要2分钟

Alpine操作系统是一个面向安全的轻型Linux发行版,它不同于通常Linux发行版,Alpine采用了musl libc和busybox以减小系统的体积和运行时资源消耗, 但功能上比busybox又完善的多,因此得到开源社区越来越多的青睐。在保持瘦身的同时,Alpine 还提供了自己的包管理工具 apk,可以通过 https://pkgs.alpinelinux.org/packages 网站上查询包信息,也可以直接通过 apk 命令直接查询和安装各种软件。

1.在docker下安装alpine

$ docker pull alpine

$ docker run -it -d --name myalpine alpine

–name myalpine 表示容器的名称

最后的alpine 表示镜像

$ 表示在终端下执行命令

可以用命令:

$ docer stop myalpine

停止一个容器

启动一个容器的命令如下:

$ docker start myalpine

无论是停止还是启动容器可以用容器的名称或者容器的Id

$ docker exec -it alpine_linux sh

注意alpine操作系统默认shell没有采用bash,采用的是sh,因此进入容器时 使用的是sh而不是bash,命令如下:

$ docker exec -it alpine_linux sh

这样docker下的alpine linux系统的环境就准备好了,可以说是比较方便的。

2.更新国内源

默认情况下alpine linux是一个精简的环境,没有安装多余的工具包,这样系统体积更小,用户可以根据自己的 需要自行安装需要的工具包。

alpine linux提供了apk包管理命令,我们可以自行安装需要的工具。默认官方的软件源比较慢,大家可以采用国内的镜像源。

采用国内阿里云的源,文件内容为:

https://mirrors.aliyun.com/alpine/v3.13/main/
https://mirrors.aliyun.com/alpine/v3.13/community/

采用中国科技大学的源,文件内容为:

https://mirrors.ustc.edu.cn/alpine/v3.13/main/
https://mirrors.ustc.edu.cn/alpine/v3.13/community/

alpine的软件源文件为 /etc/apk/repositories 修改为上面的国内任意一个镜像源就可以。

3.apk包管理命令的使用

apk包管理命令使用非常简单,不知道用什么命令,可以查看帮助

$ apk -h

apk-tools 2.12.5, compiled for x86_64.

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

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

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

帮助命令列出了apk的常用命令

比如安装curl软件包

$ apk add curl

删除已安装的curl软件包

$ apk del curl

查询curl相关的软件包

$ apk search curl