alpine系統 alpine系統是什麼 Alpine Linux 是一個基於 musl libc 和 busybox 的面向安全的輕量級 Linux 發行版。 alpine系統的特點 小巧:基於Musl libc和busybox,和busybox一樣小巧,最小的Docker鏡像只有5MB; 安全: ...
alpine系統
目錄alpine系統是什麼
Alpine Linux 是一個基於 musl libc 和 busybox 的面向安全的輕量級 Linux 發行版。
alpine系統的特點
-
小巧:基於Musl libc和busybox,和busybox一樣小巧,最小的Docker鏡像只有5MB;
-
安全:面向安全的輕量發行版;
-
簡單:提供APK包管理工具,軟體的搜索、安裝、刪除、升級都非常方便。
-
適合容器使用:由於小巧、功能完備,非常適合作為容器的基礎鏡像。
alpine鏡像下載
alpine國內源
清華大學:https://mirror.tuna.tsinghua.edu.cn/alpine/
阿裡雲:https://mirrors.aliyun.com/alpine/
網易:http://mirrors.163.com/
更換apk源
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
alpine基礎命令
apk update //更新最新鏡像源列表
apk search //查找所以可用軟體包
apk search -v //查找所以可用軟體包及其描述內容
apk search -v ‘acf*’ //通過軟體包名稱查找軟體包
apk search -v -d ‘docker’ //通過描述文件查找特定的軟體包
apk add openssh //安裝一個軟體
apk add openssh openntp vim //安裝多個軟體
apk add --no-cache mysql-client //不使用本地鏡像源緩存,相當於先執行update,再執行add
apk info //列出所有已安裝的軟體包
apk info -a zlib //顯示完整的軟體包信息
apk info --who-owns /sbin/lbu //顯示指定文件屬於的包
apk upgrade //升級所有軟體
apk upgrade openssh //升級指定軟體
apk upgrade openssh openntp vim //升級多個軟體
apk add --upgrade busybox //指定升級部分軟體包
apk del openssh //刪除一個軟體
服務管理
alpine沒有使用fedora的systemctl來進行服務管理,使用的是RC系列命令:
rc-update //主要用於不同運行級增加或者刪除服務
rc-status //主要用於運行級的狀態管理
rc-service //主用於管理服務的狀態
rc-status -a //列出系統所有服務
關閉系統
reboot //重啟系統
poweroff //關機
dockerfile創建apache鏡像
創建好目錄結構
#下載好需要使用的包
[root@localhost ~]# wget http://mirrors.aliyun.com/apache/apr/apr-1.7.0.tar.gz https://mirrors.aliyun.com/apache/apr/apr-util-1.6.1.tar.gz https://mirrors.aliyun.com/apache/httpd/httpd-2.4.54.tar.gz
#創建好一個目錄存放包和dockerfile
[root@localhost ~]# mkdir httpd
[root@localhost ~]# cd httpd
[root@localhost httpd]# mkdir files
[root@localhost httpd]# touch Dockerfile
[root@localhost httpd]# cd
[root@localhost ~]# mv *.tar.gz httpd/files/
編寫一個entrypoint.sh的腳本
[root@localhost httpd]# cd files/
[root@localhost files]# vim entrypoint.sh
#!/bin/bash
sed -i '/^ServerName/s/#//g' /usr/local/apache/conf/httpd/conf
exec "$@"
[root@localhost files]# chmod +x entrypoint.sh
編寫dockerfile
FROM alpine
LABEL MANTAINER "zxr [email protected]"
ENV apr_version=1.7.0 apr_util_version=1.6.1 httpd_version=2.4.54
ADD files/* /tmp/
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && \
adduser -SHs /sbin/nologin apache && \
apk add --no-cache -U gcc libc-dev make expat-dev pcre-dev openssl-dev libtool && \
cd /tmp/apr-${apr_version} && \
sed -i '/$RM "$cfgfile"/d' configure && \
./configure --prefix=/usr/local/apr && \
make && make install && \
cd /tmp/apr-util-${apr_util_version} && \
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install && \
cd /tmp/httpd-${httpd_version} && \
./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork && \
make && make install && \
mv /tmp/entrypoint.sh / && \
apk del gcc make && \
rm -rf /tmp/* /var/cache/*
EXPOSE 80
WORKDIR /usr/local/apache
CMD ["/usr/local/apache/bin/httpd","-D","FOREGROUND"]
ENTRYPOINT ["/bin/bash","/entrypoint.sh"]
創建鏡像
[root@localhost ~]# docker build -t xinruizhong/httpd:v2 httpd/
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xinruizhong/httpd v2 d884889149e6 5 hours ago 122MB
alpine latest c059bfaa849c 9 months ago 5.59MB
創建容器,鏈接外部存儲,並測試
[root@localhost ~]# mkdir /html/
[root@localhost ~]# cd /html/
[root@localhost html]# echo "hello world" > index.html
[root@localhost html]# cat index.html
hello world
[root@localhost ~]# docker run -dit --name web -p 80:80 -v /html/://usr/local/apache/htdocs/:Z xinruizhong/httpd:v2
3d718a9c1cca735057e99eca5fc3f3da69bccf0fa113997cb6fe05187e2bc94a
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3d718a9c1cca xinruizhong/httpd:v2 "/bin/bash /entrypoi…" 7 seconds ago Up 6 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp web
[root@localhost ~]# curl 192.168.111.139:80
hello world
上傳鏡像
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: xinruizhong
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost ~]# docker push xinruizhong/httpd:v2
The push refers to repository [docker.io/xinruizhong/httpd]
2efef2815df1: Layer already exists
6128a159deec: Layer already exists
8d3ac3489996: Layer already exists
v2: digest: sha256:7e1c94047ee828de88d62c8a146effe0befc71d66ac608a49ba9f33a9ffbb551 size: 952