Docker容器里跑centos、debian、unbuntu的几个常见问题

Docker容器里跑centos、debian、unbuntu的几个常见问题

1.无法使用 systemctl 命令的解决方案
Linux Docker中无法使用 systemd(systemctl) 相关命令的原因是 1号进程不是 init ,而是其他例如 /bin/bash ,所以导致缺少相关文件无法运行。
(System has not been booted with systemd as init system (PID 1). Can't operat)

解决方案:/sbin/init

例如:Ubuntu 18.04
docker run -tid --name ubuntu --privileged=true ubuntu:18.04  /sbin/init
docker exec -it ubuntu  /bin/bash
docker run  -d --name debian --hostname debian --net=macnet --ip 192.168.1.10 -i -t --privileged=true --restart=always  debian   /sbin/init
docker exec -it debian  /bin/bash
docker run  -d --name centos --hostname centos --net=macnet --ip 192.168.1.11 -i -t --privileged=true --restart=always  centos   /sbin/init
docker exec -it centos  /bin/bash

PS:--privilaged=true一定要加上的。

2.在Docker中使用虚拟终端容器运行了 CentOS 8 的镜像,但在执行yum命令时,提示“Failed to set locale, defaulting to C.UTF-8”
例如安装openssh-server
yum install openssh-server
设置语言环境需使用locale命令
运行locale命令出现如下提示:
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory

由上图可知,当前系统并没有安装en_US.UTF-8语言,则使用命令 dnf install glibc-langpack-en
或 dnf install langpacks-en glibc-all-langpacks -y进行语言包安装
然后运行如下命令:
echo "export LC_ALL=en_US.UTF-8"  >>  /etc/profile
echo "export LC_CTYPE=en_US.UTF-8"  >>  /etc/profile
source /etc/profile

即可解决问题。

3.在Docker中使用虚拟终端容器运行了 CentOS 8 的镜像,但在执行passwd命令时,提示“bash: passwd: command not found”
解决方法:
yum search passwd  //查找源文件
passwd.x86_64 : An utility for setting or changing passwords using PAM  //查找到的源  不一定都一样 根据自己系统的
yum install passwd.x86_64  //安装

上一篇: linux 查看公网IP和获取网卡名称
下一篇: Ubuntu奇亚高速P图:从系统安装到P图到启动矿机

访客评论
目前还没有人评论,您发表点看法?
发表评论

评论内容 (必填):