alpine 镜像使用
- alpine 是一个精简的linux镜像,里面仅仅包含了apk(alpine专属的镜像管理工具)以及linux系统内核
- alpine镜像甚至连 bash 都没有,不过echo是有的
- 使用alpine也很简单
docker run -it alpine echo "hello world"
- 由于包含的linux软件少,所以体积仅有 5M 大小,使用alpine的思想就是,需要什么软件就安装什么,其他不需要的一概不安装,以维持最小的docker镜像运行服务
- Alpine 相关地址
- Alpine 官网:https://www.alpinelinux.org/
- Alpine 官方仓库:https://github.com/alpinelinux
- Alpine 官方镜像:https://hub.docker.com/_/alpine/
- Alpine 官方镜像仓库:https://github.com/gliderlabs/docker-alpine
使用步骤
- 简要方法
- 查找 dockerHub 或 github 直接查找已经做好的alpine镜像
- 使用Dockerfile进行制作
- 从头开始
- 在apk仓库中查找到自己需要的apk进行安装
- 组装成相应的apline镜像
报错
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.4/community: temporary error (try again later)
WARNING: Ignoring APKINDEX.a2e6dac0.tar.gz: No such file or directory
-
github 上的解决方案
as pointed out by @azyata its can be a problem with the DNS settingsIf you are performing apk add inside the container, below might be helpful
From docs.docker.com:
By default, a container inherits the DNS settings of the Docker daemon
including the /etc/hosts and /etc/resolv.confTry to ping
ping dl-cdn.alpinelinux.org
if it doesn’t workCheck DNS configuration in /etc/resolve.conf in host machine, try adding
nameserver 8.8.8.8
then perform pingping dl-cdn.alpinelinux.org
if it works for you, thenRestart the docker daemon
sudo systemctl restart docker
^ This solved the problem for me. -
国内的解决方案
#vim /etc/default/docker #DOCKER_OPTS="--dns 114.114.114.114" #systemctl restart docker
-
基本上是因为dns服务有问题,换镜像源也是一个不错的方案
python-alpine镜像使用
- dockerhub地址
https://hub.docker.com/_/python
- 安装 python3.6
docker pull python:3.6.8-alpine
- 如何找到linux软件依赖的相关apk包
- 在dockerhub中搜索相应的包
- 查看其中的dockerfile文件
docker run -it python:3.6.8-alpine python--version
- 安装uwsgi
from python:3.6-alpine
# 更新并安装gcc bash
RUN apk --update add gcc linux-headers musl-dev bash-doc bash-completion
# 安装uwsgi
RUN pip install uwsgi
# 清除缓存
RUN rm -rf /var/cache/apk*
python 常用包,安装报错
apk 包通用查找方法
- apk 安装 lxml 报错
RUN apk --no-cache gcc musl-dev libxslt libxml2-dev libxml2 libxslt-dev
- apk 安装 pynacl 报错
RUN apk --no-cache add gcc linux-headers musl-dev libffi-dev build-base
- apk 安装 uwsgi 报错
RUN apk --no-cache add gcc linux-headers musl-dev
- apk 安装 cffi 报错
RUN apk --no-cache add gcc libffi-dev
- apk 安装 napalm 报错
RUN apk --no-cache add gcc linux-headers musl-dev bash-doc bash-completion libffi-dev libxslt \
libssl1.1 openssl libffi openssl-dev libxml2-dev libxml2-utils libxml2 libxslt-dev build-base