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