背景:镜像 emqx/emqx:5.8.4 用户为 emqx 无权限 系统为 debian 12
使用 root 用户创建容器登录即可
发现时间不对,换阿里源之后无法更新
更换上海时区
echo "Asia/Shanghai" > /etc/timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
更换阿里源
该方式在阿里源只更新到 debian 11 的文档
www-data@emqx-75dc55f996-tnczp:/opt/emqx$ cat /etc/apt/sources.list
deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main
deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
apt update 即可,所花费时间较久
完成之后安装测试
apt install -y vim curl net-tools
该镜像的项目存放在 /opt/emqx 下
如需更换权限如下
chown -R www-data:www-data /opt/emqx
vim /etc/passwd 将33 uid 的www-data 用户改成 /bin/bash 即可
注意其下的 /opt/emqx/data 和 /opt/emqx/log 是volume
我们在创建容器的时候还是会改变权限为 emqx 或 root
所以需要创建的时候先复制目录到宿主机,更改宿主机目录为 www-data 权限
然后在进行挂载进去持久化
docker cp emqx:/opt/emqx/data .
docker cp emqx:/opt/emqx/log .
chmod www-data:www-data -R data
chmod www-data:www-data -R log
届时创建容器才能正常写入内容成功启动服务
换成Dockerfile如下 减少了阿里源配置
FROM emqx/emqx:5.8.4
USER root
RUN date \
&& echo "Asia/Shanghai" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& date \
&& echo "deb https://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib" > /etc/apt/sources.list \
&& echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list \
&& echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib" >> /etc/apt/sources.list \
&& apt update
RUN apt install -y net-tools \
&& chown -R www-data:www-data /opt/emqx
USER www-data
注意这里构建不一定成功,因为阿里源可能还是会显示超时更新源不了
可手动启动镜像进去执行对应命令,通过 docker commit emqx emqx:test01 保存即可
启动镜像如下
docker run -d \
--name emqx \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
-p 1883:1883 \
-p 8083:8083 \
-p 8084:8084 \
-p 8883:8883 \
-p 18083:18083 \
-v /var/www/test01/emqx/data:/opt/emqx/data \
-v /var/www/test01/emqx/log:/opt/emqx/log \
emqx:test01
dockerfile示例
该镜像为 debian 12 系统
已经测试成功,如若失败,考虑手动创建容器进去更新源尝试
测试发现有时候是https的问题,改成http即可,如果还是不行有可能是强制走了https,考虑换源即可
FROM python:3.8-slim
WORKDIR /app
# 更新 apt 包索引并安装 tesseract-ocr 和相关依赖
RUN date \
&& echo "Asia/Shanghai" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& date && \
echo "deb http://mirrors.aliyun.com/debian/ stable main contrib non-free" > /etc/apt/sources.list && \
echo "deb-src http://mirrors.aliyun.com/debian/ stable main contrib non-free" >> /etc/apt/sources.list && \
apt-get update && \
apt-get install -y --no-install-recommends tesseract-ocr \
libgl1-mesa-glx \
net-tools \
procps \
tesseract-ocr-chi-sim && \
rm -rf /var/lib/apt/lists/*
# 复制代码到容器中
COPY . /app
# 设置 pip 镜像源为阿里云镜像源,并安装依赖
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
RUN groupadd -r nonroot && \
useradd -r -u 65530 -g nonroot -m nonroot && \
chown nonroot:nonroot -R /app/
WORKDIR /app
USER 65530
# 启动 Flask 应用
#CMD ["python", "app.py"]