docker centos-ssh-root 无密钥 centos image

简介:   37.1准备工作 setenforce 0 vim /etc/selinux/config SELINUX=disabled   37.2 创建docker centos-ssh-root 37.

 

37.1准备工作

setenforce 0
vim /etc/selinux/config
SELINUX=disabled

 

37.2 创建docker centos-ssh-root

37.2.1 创建dockerfile

# 选择一个已有的os镜像作为基础  
FROM centos 

# 镜像的作者  
MAINTAINER baoyou curiousby@163.com 

# 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no  
RUN yum install -y openssh-server sudo  
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config  
#安装openssh-clients
RUN yum  install -y openssh-clients

# 添加测试用户root,密码root,并且将此用户添加到sudoers里  
RUN echo "root:root" | chpasswd  
RUN echo "root   ALL=(ALL)       ALL" >> /etc/sudoers  
# 下面这两句比较特殊,在centos6上必须要有,否则创建出来的容器sshd不能登录  
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key  
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key  

# 启动sshd服务并且暴露22端口  
RUN mkdir /var/run/sshd  
EXPOSE 22  
CMD ["/usr/sbin/sshd", "-D"]

 

37.2.2 执行命令

mkdir centos-ssh-root 
cd centos-ssh-root 
vim  Dockerfile
docker build -t "curiousby/centos-ssh-root:original" .

 

37.2.3 build  运行日志



 

[root@bogon centos-ssh-root]# docker build -t  curiousby/centos-ssh-root:original .
Sending build context to Docker daemon   2.56kB
Step 1/12 : FROM centos
 ---> 328edcd84f1b
Step 2/12 : MAINTAINER curiousby curiousby@163.com
 ---> Running in a07c67ece348
 ---> a3f6c43634d0
Removing intermediate container a07c67ece348
Step 3/12 : RUN yum install -y openssh-server sudo
 ---> Running in 7319491e2cb1
Loaded plugins: fastestmirror, ovl
http://centos.ustc.edu.cn/centos/7.3.1611/updates/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed to connect to 2001:da8:d800:95::110: Network is unreachable"
Trying other mirror.
Determining fastest mirrors
 * base: mirrors.btte.net
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.nwsuaf.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:6.6.1p1-35.el7_3 will be installed
--> Processing Dependency: openssh = 6.6.1p1-35.el7_3 for package: openssh-server-6.6.1p1-35.el7_3.x86_64
--> Processing Dependency: fipscheck-lib(x86-64) >= 1.3.0 for package: openssh-server-6.6.1p1-35.el7_3.x86_64
--> Processing Dependency: libwrap.so.0()(64bit) for package: openssh-server-6.6.1p1-35.el7_3.x86_64
--> Processing Dependency: libfipscheck.so.1()(64bit) for package: openssh-server-6.6.1p1-35.el7_3.x86_64
---> Package sudo.x86_64 0:1.8.6p7-23.el7_3 will be installed
--> Running transaction check
---> Package fipscheck-lib.x86_64 0:1.4.1-5.el7 will be installed
--> Processing Dependency: /usr/bin/fipscheck for package: fipscheck-lib-1.4.1-5.el7.x86_64
---> Package openssh.x86_64 0:6.6.1p1-35.el7_3 will be installed
---> Package tcp_wrappers-libs.x86_64 0:7.6-77.el7 will be installed
--> Running transaction check
---> Package fipscheck.x86_64 0:1.4.1-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch        Version                  Repository    Size
================================================================================
Installing:
 openssh-server         x86_64      6.6.1p1-35.el7_3         updates      440 k
 sudo                   x86_64      1.8.6p7-23.el7_3         updates      735 k
Installing for dependencies:
 fipscheck              x86_64      1.4.1-5.el7              base          21 k
 fipscheck-lib          x86_64      1.4.1-5.el7              base          11 k
 openssh                x86_64      6.6.1p1-35.el7_3         updates      438 k
 tcp_wrappers-libs      x86_64      7.6-77.el7               base          66 k

Transaction Summary
================================================================================
Install  2 Packages (+4 Dependent packages)

Total download size: 1.7 M
Installed size: 4.9 M
Downloading packages:
Public key for fipscheck-1.4.1-5.el7.x86_64.rpm is not installed
warning: /var/cache/yum/x86_64/7/base/packages/fipscheck-1.4.1-5.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for sudo-1.8.6p7-23.el7_3.x86_64.rpm is not installed
http://mirrors.nwsuaf.edu.cn/centos/7.3.1611/updates/x86_64/Packages/openssh-6.6.1p1-35.el7_3.x86_64.rpm: [Errno 12] Timeout on http://mirrors.nwsuaf.edu.cn/centos/7.3.1611/updates/x86_64/Packages/openssh-6.6.1p1-35.el7_3.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
--------------------------------------------------------------------------------
Total                                               32 kB/s | 1.7 MB  00:52     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-3.1611.el7.centos.x86_64 (@CentOS)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : fipscheck-1.4.1-5.el7.x86_64                                 1/6 
  Installing : fipscheck-lib-1.4.1-5.el7.x86_64                             2/6 
  Installing : openssh-6.6.1p1-35.el7_3.x86_64                              3/6 
  Installing : tcp_wrappers-libs-7.6-77.el7.x86_64                          4/6 
  Installing : openssh-server-6.6.1p1-35.el7_3.x86_64                       5/6 
  Installing : sudo-1.8.6p7-23.el7_3.x86_64                                 6/6 
  Verifying  : openssh-6.6.1p1-35.el7_3.x86_64                              1/6 
  Verifying  : openssh-server-6.6.1p1-35.el7_3.x86_64                       2/6 
  Verifying  : sudo-1.8.6p7-23.el7_3.x86_64                                 3/6 
  Verifying  : tcp_wrappers-libs-7.6-77.el7.x86_64                          4/6 
  Verifying  : fipscheck-lib-1.4.1-5.el7.x86_64                             5/6 
  Verifying  : fipscheck-1.4.1-5.el7.x86_64                                 6/6 

Installed:
  openssh-server.x86_64 0:6.6.1p1-35.el7_3    sudo.x86_64 0:1.8.6p7-23.el7_3   

Dependency Installed:
  fipscheck.x86_64 0:1.4.1-5.el7       fipscheck-lib.x86_64 0:1.4.1-5.el7      
  openssh.x86_64 0:6.6.1p1-35.el7_3    tcp_wrappers-libs.x86_64 0:7.6-77.el7   

Complete!
 ---> a5b6b2590449
Removing intermediate container 7319491e2cb1
Step 4/12 : RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
 ---> Running in cd9fa1a6f379
 ---> b3ad6bbf3c1b
Removing intermediate container cd9fa1a6f379
Step 5/12 : RUN yum  install -y openssh-clients
 ---> Running in fadadcf8ab9b
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.nwsuaf.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package openssh-clients.x86_64 0:6.6.1p1-35.el7_3 will be installed
--> Processing Dependency: libedit.so.0()(64bit) for package: openssh-clients-6.6.1p1-35.el7_3.x86_64
--> Running transaction check
---> Package libedit.x86_64 0:3.0-12.20121213cvs.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package             Arch       Version                       Repository   Size
================================================================================
Installing:
 openssh-clients     x86_64     6.6.1p1-35.el7_3              updates     642 k
Installing for dependencies:
 libedit             x86_64     3.0-12.20121213cvs.el7        base         92 k

Transaction Summary
================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 735 k
Installed size: 2.4 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                              111 kB/s | 735 kB  00:06     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libedit-3.0-12.20121213cvs.el7.x86_64                        1/2 
  Installing : openssh-clients-6.6.1p1-35.el7_3.x86_64                      2/2 
  Verifying  : openssh-clients-6.6.1p1-35.el7_3.x86_64                      1/2 
  Verifying  : libedit-3.0-12.20121213cvs.el7.x86_64                        2/2 

Installed:
  openssh-clients.x86_64 0:6.6.1p1-35.el7_3                                     

Dependency Installed:
  libedit.x86_64 0:3.0-12.20121213cvs.el7                                       

Complete!
 ---> 7c2753e2677d
Removing intermediate container fadadcf8ab9b
Step 6/12 : RUN echo "root:root" | chpasswd
 ---> Running in 75fab0b6b241
 ---> c1cb3babeee2
Removing intermediate container 75fab0b6b241
Step 7/12 : RUN echo "root   ALL=(ALL)       ALL" >> /etc/sudoers
 ---> Running in f0c0c32b70c1
 ---> 48f3a187f13f
Removing intermediate container f0c0c32b70c1
Step 8/12 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
 ---> Running in afc9cf2b6d76
Generating public/private dsa key pair.
Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
The key fingerprint is:
13:ce:12:9b:d1:4f:5e:ee:35:b1:ed:48:60:58:92:35 root@c7947be2eb9d
The key's randomart image is:
+--[ DSA 1024]----+
|          .oE    |
|       .  .+ .   |
|      o o o + .  |
|       B = + . + |
|      + S o . = .|
|       . . . o + |
|            . . .|
|                 |
|                 |
+-----------------+
Enter passphrase (empty for no passphrase): Enter same passphrase again:  ---> 8d9c838f0e26
Removing intermediate container afc9cf2b6d76
Step 9/12 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
 ---> Running in d7131a2534c2
Generating public/private rsa key pair.
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
c1:dc:54:6c:45:d8:35:c3:cf:ac:fb:35:22:6a:2e:0e root@c7947be2eb9d
The key's randomart image is:
+--[ RSA 2048]----+
|          .o.=++.|
|       o o  + ..o|
|        + ..   o.|
|         .      +|
|        S      . |
|              .  |
|     E     . . o.|
|      .. .. . o o|
|      ..+o     ..|
+-----------------+
Enter passphrase (empty for no passphrase): Enter same passphrase again:  ---> 0f71202ee047
Removing intermediate container d7131a2534c2
Step 10/12 : RUN mkdir /var/run/sshd
 ---> Running in e3f36ab8616f
 ---> 6007b08d3e2b
Removing intermediate container e3f36ab8616f
Step 11/12 : EXPOSE 22
 ---> Running in 653c57effb5a
 ---> 6533c53d9497
Removing intermediate container 653c57effb5a
Step 12/12 : CMD /usr/sbin/sshd -D
 ---> Running in 46accc61a713
 ---> 265bd8a128b3
Removing intermediate container 46accc61a713
Successfully built 265bd8a128b3
Successfully tagged curiousby/centos-ssh-root:original

 

 

37.2.4  build  验证



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者 

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

 

个人主页http://knight-black-bob.iteye.com/



 
 
 谢谢您的赞助,我会做的更好!

目录
相关文章
|
24天前
|
存储 Linux Docker
centos系统清理docker日志文件
通过以上方法,可以有效清理和管理CentOS系统中的Docker日志文件,防止日志文件占用过多磁盘空间。选择合适的方法取决于具体的应用场景和需求,可以结合手动清理、logrotate和调整日志驱动等多种方式,确保系统的高效运行。
23 2
|
1月前
|
安全 Linux Shell
docker运行centos提示Operation not permitted
通过上述步骤,可以有效排查和解决在Docker中运行CentOS容器时遇到的"Operation not permitted"错误。这些措施涵盖了从权限配置、安全策略到容器运行参数的各个方面,确保在不同环境和使用场景下都能顺利运行容器。如果你需要进一步优化和管理你的Docker环境
62 3
|
2月前
|
Linux Docker 容器
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
本篇博客重在讲解Centos安装docker,经博主多次在不同服务器上测试,极其的稳定,尤其是阿里的服务器,一路复制命令畅通无阻。
1050 4
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
|
2月前
|
Java jenkins 持续交付
Centos7下docker的jenkins下载并配置jdk与maven
通过上述步骤,您将成功在CentOS 7上的Docker容器中部署了Jenkins,并配置好了JDK与Maven,为持续集成和自动化构建打下了坚实基础。
114 1
|
2月前
|
NoSQL Linux Redis
Docker学习二(Centos):Docker安装并运行redis(成功运行)
这篇文章介绍了在CentOS系统上使用Docker安装并运行Redis数据库的详细步骤,包括拉取Redis镜像、创建挂载目录、下载配置文件、修改配置以及使用Docker命令运行Redis容器,并检查运行状态和使用Navicat连接Redis。
273 3
|
2月前
|
存储 Linux 开发者
虚拟机centos7.9一键部署docker
本文介绍了如何在 CentOS 7.9 虚拟机上安装 Docker 社区版 (Docker-ce-20.10.20)。通过使用阿里云镜像源,利用 `wget` 下载并配置 Docker-ce 的 YUM 仓库文件,然后通过 `yum` 命令完成安装。安装后,通过 `systemctl` 设置 Docker 开机自启并启动 Docker 服务。最后,使用 `docker version` 验证安装成功,并展示了客户端与服务器的版本信息。文中还提供了列出所有可用 Docker-ce 版本的命令。
208 0
虚拟机centos7.9一键部署docker
|
2月前
|
网络虚拟化 Docker 容器
docker Desktop报错 error pulling image configuration 处理
docker Desktop报错 error pulling image configuration 处理
42 0
|
3月前
|
存储 Linux Docker
CentOS 7.6安装Docker实战案例及存储引擎和服务进程简介
关于如何在CentOS 7.6上安装Docker、介绍Docker存储引擎以及服务进程关系的实战案例。
152 3
CentOS 7.6安装Docker实战案例及存储引擎和服务进程简介
|
3月前
|
Docker 容器
centos7.3之安装docker
centos7.3之安装docker
|
监控 Linux 应用服务中间件
Docker——Image的原理(四)(4)
Docker——Image的原理(四)(4)
113 0
Docker——Image的原理(四)(4)