Alpine Linux是基於musl libc和busybox的面向安全的輕量級Linux發行版。有些命令用法和包名和centos/ubuntu 之類的不一樣
包管理工具apk
apk add 包名 #安裝 xx包
apk del 包名 #卸載 xx包
apk update 更新源
apk 的源
使用阿里雲
a. 編輯
/etc/apk/repositories
b. 將里面 dl-cdn.alpinelinux.org 的 改成 mirrors.aliyun.com ; 保存退出即可
尋找apk 的包名
在阿里雲的鏡像地址中搜索相關的包名即可
http://mirrors.aliyun.com/alpine/v3.11/main
http://mirrors.aliyun.com/alpine/v3.11/community
添加用戶
使用adduser 而不是useradd
1.首先在本地目錄下創建一個測試頁,如下:
vim index.html
<h1> nginx test !!! </h1>

2.設置alpine apk的源,創建repositories文件,如下:
vim repositories
http://mirrors.aliyun.com/alpine/v3.11/main
http://mirrors.aliyun.com/alpine/v3.11/community

3.編寫Dockerfile
FROM alpine:latest MAINTAINER yang <yang@163.com> ENV NG_VERSION nginx-1.18.0 COPY repositories /etc/apk/repositories RUN apk update && apk add iotop gcc libgcc libc-dev libcurl libc-utils pcre-dev zlib-dev libnfs make pcre pcre2 zip unzip net-tools wget openssl openssl-dev ADD http://nginx.org/download/$NG_VERSION.tar.gz /usr/local/ WORKDIR /usr/local/nginx-1.18.0 RUN adduser -D -s /sbin/nologin nginx \ && cd /usr/local/ \ && tar xzvf $NG_VERSION.tar.gz -C /usr/local/ \ && cd /usr/local/$NG_VERSION \ && ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-http_gzip_static_module \ && make && make install \ && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ADD index.html /usr/local/nginx/html VOLUME /mnt/acs_mnt/nas/nasfiles/kb ENV PATH /usr/local/nginx/sbin:$PATH EXPOSE 80/tcp ENTRYPOINT ["nginx"] CMD ["-g","daemon off;"]

4.構建nginx鏡像,如下:
docker build -t nginx:v101 .


5.查看制作好的鏡像
docker images

6.啟動一個容器
dokcer run -it -d --name nginx -p 8989:80 nginx:v101

7.使用啟動容器的主機IP+映射端口,訪問測試:
測試之前要看主機的防火牆是否開放了端口:
永久開放8989端口:firewall-cmd --zone=public --add-port=8989/tcp --permanent
使 其 生 效:firewall-cmd --reload
查看端口是否開啟:firewall-cmd --list-port


