Docker 环境下安装 Centos

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/AnselLyy/article/details/84726831

环境

  • Docker 18.06.1-ce-rc1
  • Centos 7.4

安装

  • Centos 7.5

安装配置步骤

引入 Centos 镜像

docker pull centos
docker run -itd centos /bin/bash

配置 Centos

# 进入容器
docker attach [Container ID]

# 安装网络模块,用于查看 ip 地址
yum install iproute

# 修改 root 密码
passwd

# 安装 ssh
yum install openssh-server -y

# 生成公钥、私钥
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t rsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t rsa -f /etc/ssh/ssh_host_ed25519_key

# 退出容器 [ctrl + P + Q]

# 保存镜像
docker stop [container ID]
docker commit [container ID] anselee/centos:latest
docker rm [container ID]

# you can pull from docker hub: docker pull anselee/centos

启动 Centos

# 开启特权模式和 init,以此开启 systemctl 命令权限
docker run --name mongo_2 -d -p 5002:22 -p 27018:27018 --privileged=true anselee/centos:latest /usr/sbin/init

# 远程 ssh 连接 5002 端口

猜你喜欢

转载自blog.csdn.net/AnselLyy/article/details/84726831