咱們在進行URLOS應用開發時,常常會用到一些基礎系統鏡像,如:ubuntu、CentOS、Debian等,咱們能夠經過docker pull命令直接拉取官方鏡像。html
root@ubuntu:~# docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
898c46f3b1a1: Already exists
63366dfa0a50: Already exists
041d4cd74a92: Already exists
6e1bee0f8701: Already exists
Digest: sha256:017eef0b616011647b269b5c65826e2e2ebddbe5d1f8c1e56b3599fb14fabec8
Status: Downloaded newer image for ubuntu:18.04
root@master-node:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 18.04 94e814e2efa8 6 weeks ago 88.9MB
root@ubuntu:~#
複製代碼
以上是從docker官方拉取的ubuntu18.04鏡像,咱們能夠基於此鏡像製做相關的應用,好比LNP網站環境、LAP網站環境、Nodejs環境等等。簡單理解,就是說幾乎全部的docker應用都是在這些鏡像上層層打包後獲得的,應用的最終體積也許有幾百M甚至上G,咱們如何爲應用瘦身以減小對磁盤的消耗呢?node
docker官方爲咱們打造了Alpine。 Alpine 的意思是「高山的」,好比 Alpine plants高山植物,Alpine skiing高山滑雪、the alpine resort阿爾卑斯山勝地,其實Alpine是一個操做系統。linux
Alpine 操做系統是一個面向安全的輕型 Linux 發行版。目前 Docker 官方已開始推薦使用 Alpine 替代以前的 Ubuntu 作爲基礎鏡像環境。這樣會帶來多個好處。包括鏡像下載速度加快,鏡像安全性提升,主機之間的切換更方便,佔用更少磁盤空間等。nginx
Alpine的特色:docker
一、小巧:基於Musl libc和busybox,和busybox同樣小巧,最小的Docker鏡像只有5MB;ubuntu
二、安全:面向安全的輕量發行版;vim
三、簡單:提供APK包管理工具,軟件的搜索、安裝、刪除、升級都很是方便。安全
四、適合容器使用:因爲小巧、功能完備,很是適合做爲容器的基礎鏡像。bash
在製做URLOS應用時,咱們能夠選擇Alpine做爲系統基礎鏡像,這樣一來可有效下降應用的大小,方便其餘用戶下載安裝。如今咱們開始使用Alpine(若是你的系統中沒有安裝docker,建議先安裝URLOS,由於它自帶了docker)。服務器
docker下運行Alpine 使用docker pull
命令拉取Alpine鏡像
root@ubuntu:~# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
bdf0201b3a05: Pull complete
Digest: sha256:28ef97b8686a0b5399129e9b763d5b7e5ff03576aa5580d6f4182a49c5fe1913
Status: Downloaded newer image for alpine:latest
root@ubuntu:~#
複製代碼
使用docker images
命令查看鏡像
root@ubuntu:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest cdf98d1859c1 2 weeks ago 5.53MB
ubuntu 18.04 94e814e2efa8 6 weeks ago 88.9MB
root@ubuntu:~#
複製代碼
能夠看到alpine鏡像只有5.53MB,而ubuntu鏡像則有88.9MB,Alpine的體積優點很是明顯。
下面運行鏡像
root@ubuntu:~# docker run -it --name myalpine alpine
/ #
複製代碼
/etc/hostname
使用新設置的主機名馬上生效,執行以下命令:
hostname -F /etc/hostname
複製代碼
/etc/hosts
文件內容爲:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 a9efe865a8e6
192.168.43.121 www.urlos.com
複製代碼
/etc/resolv.conf
文件內容爲:
#neeanew Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.43.1
複製代碼
/etc/network/interfaces
文件內容爲:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.43.121
netmask 255.255.255.0
gateway 192.168.43.1
複製代碼
修改完相關配置之後,從新啓動網絡服務:
/etc/init.d/networking restart
複製代碼
Alpine的源文件爲:
/etc/apk/repositories
默認的源地址爲:dl-cdn.alpinelinux.org/
能夠編輯源文件 /etc/apk/repositories
採用國內阿里雲的源,文件內容爲:
mirrors.aliyun.com/alpine/v3.6…
mirrors.aliyun.com/alpine/v3.6…
若是採用中國科技大學的源,文件內容爲:
mirrors.ustc.edu.cn/alpine/v3.6…
mirrors.ustc.edu.cn/alpine/v3.6…
alpine 提供了很是好用的apk軟件包管理工具,
能夠方便地安裝、刪除、更新軟件。
命令:apk search
,如查詢vim軟件包:
/ # apk search vim
neovim-doc-0.2.0-r0
faenza-icon-theme-vim-1.3.1-r4
docker-vim-17.05.0-r0
vim-doc-8.0.0595-r0
py-jinja2-vim-2.9.6-r0
vimdiff-8.0.0595-r0
asciidoc-vim-8.6.9-r2
neovim-lang-0.2.0-r0
vim-8.0.0595-r0
neovim-0.2.0-r0
nginx-vim-1.12.2-r2
msmtp-vim-1.6.6-r1
protobuf-vim-3.1.0-r1
gst-plugins-base1-1.10.4-r1
mercurial-vim-4.5.2-r0
/ #
複製代碼
命令:apk add
,如安裝vim軟件包:
/ # apk add vim
(1/5) Installing lua5.2-libs (5.2.4-r2)
(2/5) Installing ncurses-terminfo-base (6.0_p20171125-r1)
(3/5) Installing ncurses-terminfo (6.0_p20171125-r1)
(4/5) Installing ncurses-libs (6.0_p20171125-r1)
(5/5) Installing vim (8.0.0595-r0)
Executing busybox-1.29.3-r10.trigger
OK: 39 MiB in 19 packages
/ #
複製代碼
命令:apk del
,如卸載vim軟件:
/ # apk del vim
(1/5) Purging vim (8.0.0595-r0)
(2/5) Purging lua5.2-libs (5.2.4-r2)
(3/5) Purging ncurses-libs (6.0_p20171125-r1)
(4/5) Purging ncurses-terminfo (6.0_p20171125-r1)
(5/5) Purging ncurses-terminfo-base (6.0_p20171125-r1)
Executing busybox-1.29.3-r10.trigger
OK: 6 MiB in 14 packages
/ #
複製代碼
命令:apk --help
以上是Alpine最基本的使用方法,更多URLOS開發教程與docker容器教程請訪問URLOS官網獲取。
URLOS官網:www.urlos.com/ URLOS安裝方法:www.urlos.com/center-home… URLOS開發交流QQ羣:695164700,147882180 URLOS微信公衆號: