Docker运行centos7

Docker 安装 centos7 :

步骤:

1.使用Docker创建虚拟网络:

# 创建一个网段为192.168.0.0/24的虚拟网络,名字为centosNet
docker network create --subnet=192.168.0.0/24  centosNet

# 查看
docker network ls

2.创建容器;

#"--privileged=true" 参数使得容器具有对主机系统设备和内核功能的完全访问权限。
#容器运行的是 CentOS 7 镜像,主进程为 "/sbin/init"。

docker run -itd --name node2 --net centosNet --ip 192.168.0.2 --privileged=true centos:7.9.2009 /sbin/init

3.安装ssh服务:

yum -y install net-tools openssh-server openssh-clients vim 

4.配置sshd_config文件开启ssh端口和监听服务,配置容器密码:

vim /etc/ssh/sshd_config

#将文件中,关于监听端口、监听地址前的 # 号去除
 
Port 22                    //端口
#AddressFamily any
ListenAddress 0.0.0.0      //监听地址
ListenAddress : :


# 保存退出后启动sshd服务
systemctl start sshd
# 查看sshd服务状态
systemctl status sshd


遇到的问题:

每次启动容器后都需要,source /etc/profile;

解决办法:在 ~/.bashrc 里面加一句

source /etc/profile

2.解决systemctl不能用的问题:

# 替换:(whereis systemctl)
wget https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py -O /usr/bin/systemctl

#
chmod a+x /usr/bin/systemctl
posted @   小小酥oAo  阅读(256)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示