新增Docker ssh管理
This commit is contained in:
34
Docker/Dockerfile/Centos/Dockerfile-ssh
Normal file
34
Docker/Dockerfile/Centos/Dockerfile-ssh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
FROM centos:7
|
||||||
|
|
||||||
|
# 设置环境变量(登录密码)
|
||||||
|
ARG ROOT_PASSWORD
|
||||||
|
|
||||||
|
# 切换镜像源
|
||||||
|
RUN mv /etc/yum.repos.d/* /tmp \
|
||||||
|
&& curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
||||||
|
|
||||||
|
# 安装SSH服务及相关工具
|
||||||
|
RUN yum install -y \
|
||||||
|
openssh-server \
|
||||||
|
openssh-clients \
|
||||||
|
passwd \
|
||||||
|
sudo \
|
||||||
|
vim \
|
||||||
|
net-tools \
|
||||||
|
iproute \
|
||||||
|
which \
|
||||||
|
&& yum clean all
|
||||||
|
|
||||||
|
# 配置SSH服务
|
||||||
|
RUN ssh-keygen -A \
|
||||||
|
&& mkdir -p /var/run/sshd \
|
||||||
|
&& echo "root:${ROOT_PASSWORD}" | chpasswd \
|
||||||
|
&& sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config \
|
||||||
|
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
|
||||||
|
&& sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
|
||||||
|
|
||||||
|
# 开放SSH端口
|
||||||
|
EXPOSE 22
|
||||||
|
|
||||||
|
# 启动SSH服务
|
||||||
|
CMD ["/usr/sbin/sshd", "-D"]
|
||||||
@@ -2,9 +2,37 @@
|
|||||||
|
|
||||||
> 本文作者:丁辉
|
> 本文作者:丁辉
|
||||||
|
|
||||||
# Centos 镜像构建
|
# Centos
|
||||||
|
|
||||||
```bash
|
- Centos 基础镜像构建
|
||||||
./build.sh
|
|
||||||
```
|
```bash
|
||||||
|
./build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- Centos 配置策略允许外部通过 SSH 登录
|
||||||
|
|
||||||
|
1. 构建镜像
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build --build-arg ROOT_PASSWORD=password -t centos-ssh:7 -f Dockerfile-ssh .
|
||||||
|
```
|
||||||
|
|
||||||
|
**参数解释**
|
||||||
|
|
||||||
|
`ROOT_PASSWORD`:配置登录 Centos 默认 ROOT 密码
|
||||||
|
|
||||||
|
2. 启动镜像并登录
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run --name centos -p 2222:22 -d centos-ssh:7
|
||||||
|
```
|
||||||
|
|
||||||
|
3. 登录
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh -p 2222 root@IP
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user