debian 12 系统容器更换阿里源和用户权限

背景:镜像 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
相关推荐
测试人社区-千羽4 分钟前
Apple自动化测试基础设施(XCTest/XCUITest)面试深度解析
运维·人工智能·测试工具·面试·职场和发展·自动化·开源软件
秋刀鱼 ..5 分钟前
第二届电气、自动化与人工智能国际学术会议(ICEAAI 2026)
大数据·运维·人工智能·机器人·自动化
测试人社区—小叶子15 分钟前
移动开发新宠:用Flutter 4.0快速构建跨平台应用
运维·网络·人工智能·测试工具·flutter·自动化
RisunJan18 分钟前
Linux命令-getsebool命令(查询 SELinux 策略中各项布尔值(boolean)的当前状态)
linux·运维·服务器
秋刀鱼 ..27 分钟前
2026年光学、物理学与电子信息国际学术会议(OPEI 2026)
运维·人工智能·科技·金融·机器人
乾元33 分钟前
Syslog / Flow / Telemetry 的 AI 聚合与异常检测实战(可观测性)
运维·网络·人工智能·网络协议·华为·自动化·ansible
liebe1*144 分钟前
第八章 防火墙高可靠性技术
运维·服务器·网络
DN金猿1 小时前
jenkins 权限控制(用户只能看指定的项目)
linux·运维·服务器·jenkins
長安一片月1 小时前
操作系统之进程和线程
linux·运维·服务器
邵小的运维之路1 小时前
静态路由与 BFD 联动
运维·网络·智能路由器