gpt4 book ai didi

docker - 在 docker 容器内使用 systemctl 启动 ssh

转载 作者:行者123 更新时间:2023-12-03 00:05:59 39 4
gpt4 key购买 nike

我是 Docker 的初学者;我已从 Hub 中提取了 CentOS 7 镜像并运行它;

我需要从我的主机 ssh 到 docker 容器(CentOS 7)。

使用docker检查container-id获取docker容器的IP

我已经使用安装了以下内容

 initscripts
systemd.x86_64
systemd-libs.x86_64
open-ssh
firewalld
net-tools

当我尝试启动防火墙打开 ssh(22) 端口时

[root@a6f3e3eb095c ~]# systemctl  start firewall
Failed to get D-Bus connection: Operation not permitted

也尝试过,

[root@a6f3e3eb095c ~]# /usr/lib/systemd/systemd --system &
[1] 353
[root@a6f3e3eb095c ~]# systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
Detected virtualization xen.
Detected architecture x86-64.

Welcome to CentOS Linux 7 (Core)!

Set hostname to <a6f3e3eb095c>.
Cannot determine cgroup we are running in: No such file or directory
Failed to allocate manager object: No such file or directory

[1]+ Exit 1 /usr/lib/systemd/systemd --system

如何在docker容器内启动防火墙/ssh?

最佳答案

在 docker 容器内运行以下命令:

yum update -y glibc-common

yum install -y sudo passwd openssh-server openssh-clients tar screen crontabs strace telnet perl libpcap bc patch ntp dnsmasq unzip pax which

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

yum install -y hiera lsyncd sshpass rng-tools

service sshd start;

sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config;

sed -i 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config;

sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config;

sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Base.repo

mkdir -p /root/.ssh/;

rm -f /var/lib/rpm/.rpm.lock;

echo "StrictHostKeyChecking=no" > /root/.ssh/config;

echo "UserKnownHostsFile=/dev/null" >> /root/.ssh/config

echo "root:password" | chpasswd

(或)

只需在 docker hub 中使用 ssh 拉取 centos 的 docker 镜像即可

https://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=centos+ssh&starCount=0

https://hub.docker.com/r/kinogmt/centos-ssh/

https://hub.docker.com/r/jdeathe/centos-ssh/

关于docker - 在 docker 容器内使用 systemctl 启动 ssh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47506171/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com