0x01 简介
Alpine Linux是一个面向安全应用的轻量级Linux发行版。它采用了musl libc和busybox以减小系统的体积和运行时资源消耗,同时还提供了自己的包管理工具apk,因为体量轻可用于构建容器基础镜像。
apk常用命令
## 更新最新本地镜像源
$ apk update
## 升级指定软件包
$ apk add --upgrade busybox
## 安装包
$ apk del openssh
## 卸载包
$ apk del openssh
## 搜索可用软件包
$ apk search wget
## 列出所有已安装的软件包
$ apk info
## 显示完整的软件包信息
$ apk info -a wget
## 显示指定文件属于的包
$ apk info --who-owns /usr/bin/nc
构建容器镜像demo
- 构建一个sshd
FROM alpine
MAINTAINER alpine_sshd (admin@attacker.club.com)
# 替换阿里云的源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 更新源、安装openssh 并修改配置文件和生成key
RUN apk update && \
apk add --no-cache openssh tzdata && rm -rf /var/cache/apk/* && \
ssh-keygen -t dsa -P "" -f /etc/ssh/ssh_host_dsa_key && \
ssh-keygen -t rsa -P "" -f /etc/ssh/ssh_host_rsa_key && \
ssh-keygen -t ecdsa -P "" -f /etc/ssh/ssh_host_ecdsa_key && \
ssh-keygen -t ed25519 -P "" -f /etc/ssh/ssh_host_ed25519_key && \
ssh-keygen -A && \
sed -i "/PermitRootLogin/c PermitRootLogin yes" /etc/ssh/sshd_config && \
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config
# 设置默认密码,清空motd
RUN echo "root:123456" | chpasswd && \
echo > /etc/motd && \
echo '''PS1="\[\e[37;1m\][\[\e[32;1m\]\u\[\e[37;40m\]@\[\e[34;1m\]\h \[\e[0m\]\t \[\e[35;1m\]\W\[\e[37;1m\]]\[\e[m\]/\\$" ''' >>/etc/profile
# 开放22端口
EXPOSE 22
# 执行ssh启动命令
CMD ["/usr/sbin/sshd", "-D"]
- python应用
FROM python:3.8-alpine
WORKDIR /home/app
COPY requirements.txt /home/app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add gcc curl vim busybox-extras \
libldap libjpeg jpeg-dev libc-dev musl-dev \
python-dev openldap-dev zlib-dev libffi-dev
RUN pip --no-cache-dir install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com --upgrade pip
RUN pip --no-cache-dir install -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com -r requirements.txt
COPY . /home/app
RUN rm -rf /home/app/env /home/app/db.sqlite3 /home/app/logs/access.log /root/.cache/pip /var/cache/apk/*
EXPOSE 8000
# RUN python manage.py makemigrations && python manage.py migrate
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:8000"]