转载地址:https://my.oschina.net/jywm/blog/754123

一、查看当前镜像

[root@iZ25av9xi4hZ ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/centos    latest              980e0e4c79ec        3 weeks ago         196.7 MB
[root#

上面的centos 是通过docker pull centos拉取获得的最新centos7 版本

二、创建一个容器,并配置ssh、tomcat、jdk

2.1 创建一个容器(命名为base_centos)

# docker run -it --name base_centos centos:latest /bin/bash
[root@cf6b692adf02 /] 2.2 安装net-tools,iproute 

net-tools 可以使用ifconfig等命令

# yum install -y net-tools

iproute 可以使用ip add 查看网络配置

# yum install -y iproute

3、sshd安装,及配置

3.1 安装openssh

# yum install -y openssh
[root# yum install -y openssh-server
[root# yum install -y openssh-clients

3.2 配置私钥

输入 命令显示如下,分别配置私钥。其中输入的地方全部选择enter键跳过

[root@cf6b692adf02 /]#/usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
[root@cf6b692adf02 /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): Enter same passphrase again: 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: d6:46:9c:ef:bf:5d:45:95:59:50:b9:9b:fa:a6:1d:3d root@cf6b692adf02 The key's randomart image is: +--[ RSA 2048]----+ | .oO| | . . +.| | + o| | o . o | | S o . +| | . . . oo| | . .Eo| | o.o+| | .*+.| +-----------------+
# ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
Generating private ecdsa key pair.
Enter in /etc/ssh/ssh_host_ecdsa_key. Your in /etc/ssh/ssh_host_ecdsa_key.pub. The key fingerprint is: 7f:ad:3b:5f:93:c2:6e:f0:05:f8:75:80:18:f8:ba:83 root@cf6b692adf02 The key's randomart image is: +--[ECDSA 256]---+ | ..o . | | . . . . | | . . . | | .. . ..| | S. . o .| | .. ..o ..| | . .. +ooo.| | E o .o+...| | . +=. | +-----------------+ [root@cf6b692adf02 /]#
[root@cf6b692adf02 /]# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
Generating private ed25519 key pair.
Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /etc/ssh/ssh_host_ed25519_key. Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub. The key fingerprint is: 44:93:0d:94:eb:e2:a4:3e:a3:fe:ab:e7:4f:2e:f0:44 root@cf6b692adf02 The key's randomart image is: +--[ED25519 256--+ | .==       |
|       .o..      |
|        ..       |
|    E  ..        |
|   .   .S        |
|  . . o .        |
|   + +..         |
|    Bo.          |
| .+B=*o          |
+-----------------+
[root@cf6b692adf02 /] 最后执行一次,再查看sshd进程,发现是启动的。 
#ps -a | grep sshd
[root@cf6b692adf02 /]# /usr/sbin/sshd [root@cf6b692adf02 /]# ps -ef | grep sshd root 109 1 0 13:16 ? 00:00 /usr/sbin/sshd root 128 22 ? 00 grep --color=auto sshd [root@cf6b692adf02 /] 将sshd 加入开机自启(/etc/rc.d/rc.local)
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
# In contrast to prevIoUs versions due to parallel execution during boot
# this script will NOT be run after all other services.
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/usr/sbin/sshd

4、tomcat 安装及配置

4.1 安装wget命令

#yum install -y wget

4.2 下载tomcat8

[root@cf6b692adf02 tmp]# wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.5.5/bin/apache-tomcat-8.5.5.tar.gz

4.3 安装tomcat8,并加入开机自启

5、jdk 安装配置

@cf6b692adf02
tmp]#wget http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-linux-x64.rpm?AuthParam=1475328855_221393517c76253d935635ef2ec114d1 [root#mv jdk-8u101-linux-x64.rpm?AuthParam=1475328855_221393517c76253d935635ef2ec114d1 jdk.rpm [root#rpm -ivh jdk.rpm Preparing... ################################# [100%] Updating / installing... 1:jdk1.8.0_101-2000:1.8.0_101-fcs ################################# [100%] Unpacking JAR files... tools.jar... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar... [root# java -version java version "1.8.0_101" Java(TM) SE Runtime Environment (build 0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13,mixed mode) [root jdk rpm安装在/usr/java/jdk1.8.0_101/jre/bin/java

5、写脚本启动关闭tomcat

5.1 安装vim

@cf6b692adf02
tomcat]# yum install vim* -y

五、

5.1 创建新的镜像文件

将之前做的容器弄成镜像文件,取名base:latest

[root@iZ25av9xi4hZ ~]# docker commit cf6b692adf02 base:latest
sha256:a90294e9b9b5b375c895ff32bfd34120797e8391bdbcbfa53b3792d636280f70

查看镜像下载所有的镜像文件

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
base                latest              a90294e9b9b5        2 minutes ago       934.9 MB
docker.io/centos    latest               5.2创建tomcat_cl 容器,并设置其ssh对于宿主机器的10022端口,8080端口对应宿主机器的10088端口 
# docker run -p 10022:22 -p 10088:8080 --name tomcat_cl -d base:latest /usr/sbin/sshd -D
e21a8af9269cd06b3950f59020de4d29723580c20bd35334ea6ff3fed28fb043 [root# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e21a8af9269c base:latest "/usr/sbin/sshd -D" 7 seconds ago Up 6 seconds 0.010022->22/tcp,10088->8080/tcp tomcat_cl cf6b692adf02 centos:latest "/bin/bash" About an hour ago Up 10 minutes base_centos [root 5.3 ssh登录容器
[root@iZ25av9xi4hZ ~]# ssh root@127.0.0.1 -p 10022
The authenticity of host '[0.1]:10022 ([10022)' can't be established. ECDSA key fingerprint is 7f:ad:3b:5f:93:c2:6e:f0:05:f8:75:80:18:f8:ba:83. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[10022' (ECDSA) to the list of kNown hosts. root@0.1's password:
Permission denied,please try again.

开始没有创建密码,所以叫修改一下密码

# docker exec -it tomcat_cl /bin/bash
[root@e21a8af9269c /]# passwd Changing password for user root. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully. [root@e21a8af9269c /]# exit exit [root@iZ25av9xi4hZ ~] 再次ssh ,可以正常进入
# ssh root@127.0.0.1 -p 10022
root@127.1's password: [root@e21a8af9269c ~]#

5.4 在宿主机器检查对应的映射端口

# ps -aux | grep 10022
root     17088  0  1.5 188360 15708 ?        Sl   22:41   0:00 docker-proxy -proto tcp -host-ip 0 -host-port 10022 -container-ip 192.168.3 -container-port 22
root     17218  112660   960 pts/3    S+   46   grep --color=auto 10022
[root@iZ25av9xi4hZ ~]# ps -aux | grep 10088
root     17079  131020 15652 ?        Sl   10088 -container-ip 8080
root     17226  112664   47   10088
[root@iZ25av9xi4hZ ~] 进入容器去启动tomcat 
@iZ
25av9xi4hZ ~]127.0.0.1 -p 10022 root@.1's password: [root@e21a8af9269c ~]# ps -ef | grep java root 178 162 14:52 pts/00 grep --color=auto java [root@e21a8af9269c ~]# /app/apache-tomcat-cl/bin/startup.sh Using CATALINA_BASE: /app/apache-tomcat-cl CATALINA_HOME: /app/apache-tomcat-cl CATALINA_TMPDIR: /app/apache-tomcat-cl/temp JRE_HOME: /usr CLAsspATH: /app/apache-tomcat-cl/bin/bootstrap.jar:/app/apache-tomcat-cl/bin/tomcat-juli.jar Tomcat started. [root193 1 56 02 /usr/bin/java -Djava.util.logging.config.file=/app/apache-tomcat-cl/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -classpath /app/apache-tomcat-cl/bin/bootstrap.jar:/app/apache-tomcat-cl/bin/tomcat-juli.jar -Dcatalina.base=/app/apache-tomcat-cl -Dcatalina.home=/app/apache-tomcat-cl -Djava.io.tmpdir=/app/apache-tomcat-cl/temp org.apache.catalina.startup.Bootstrap start root 210 @e21a8af9269c ~]#

通过浏览器输入宿主ip:端口。可以看到tomcat运行起来了。

centos 实现ssh远程连接docker的更多相关文章

  1. macos – 运行brew命令充满了’同意Xcode / iOS许可证需要管理员权限,请通过sudo以root身份重新运行.’

    所以我跑了:如果滚动到底部,可以输入“同意”,然后就可以了.

  2. iOS – 友好的NSDate格式

    我需要在我的应用程序中显示帖子的日期给用户,现在我用这种格式:“5月25日星期五”.如何格式化NSDate以阅读“2小时前”的内容?使其更加用户友好.解决方法NSDateFormatter不能做这样的事情;你将需要建立自己的规则.我想像:所以这是打印’x分钟前’或’x小时前’从日期起24小时,通常是一天.

  3. osx – 无法创建目录/ var / teamsserver

    OpenSSH_6.2p2,OSSLShim0.9.8r8Dec2011debug1:Readingconfigurationdata/etc/ssh_configdebug1:/etc/ssh_configline20:Applyingoptionsfor*debug1:Connectingto1.2.3.4[1.2.3.4]portPORT.debug1:Connectionestablished.Couldnotcreatedirectory‘/var/teamsserver/.ssh’.debug

  4. ios – Xcode Server 4.0 git从构建触发脚本推送

    我为一个托管在github上的项目安装了一个XcodeBot.我按照步骤和设置机器人来使用我现有的SSH密钥.验证成功,项目结算和建立.然后,我在预触发器操作中添加了一个shell脚本,它增加了plist中的版本,将其标记,并将该更改提交到github.但是当我尝试从shell脚本执行gitpush时,我得到:–推送到git@github.com:spex-app/spex-ios.git权限被拒

  5. ios – Xcode上传错误:无法打开ssh会话. (16)

    注意:我们终于上传了该应用程序,但是我们并没有真正解决这个问题,所以如果有人可以分享一些有关这个问题的宝贵意见或经验,我将不胜感激.我也检查了以下2个类似的问题,但这些没有帮助:>Erroruploadingiosapplicationtoitunesconnect“failedtoopensshsession(16)”>AppStoresubmission/distributionerror“f

  6. ios – Objective-C中的混合或多重继承?

    换句话说,是否可以创建一个可以从这两个子类继承的抽象类,然后只覆盖两者之间不同的方法?我到目前为止所知道的>我知道Objective-C不支持多重继承>我知道我可以使用Categories添加常用的方法,但是我不认为这会解决覆盖init方法或添加私有属性解决方法建立在Amin的答案上,这是怎么做的呢?

  7. ios – 仅适用于iPad的Settings.bundle?

    我有一种情况需要通过设置应用程序为我的应用程序提供一个设置.我的应用程序是通用的,但这个特殊的设置只在iPad上有意义,所以我只希望我的应用程序显示在iPad上的设置中.这可能吗?

  8. ios – Swift 4设置捆绑,获取默认值

    我创建了一个包含大约8个切换开关的设置包.我想要做的是从设置包中获取默认值.目前我现在有这两种方法:我在viewDidLoad中调用这些方法然而,这并没有得到我的默认值.如果我关闭应用程序,打开设置,调整设置并重新打开应用程序,这会产生正确的值.有没有获得默认设置?

  9. 记一次云计算测试实验-openstack-icehouse-安装swift

    -----------------------controller:---------------------------------sourceadmin-openrc.shkeystoneuser-create--name=swift--pass=000000--email=swift@localhostkeystoneuser-role-add--user=swift--tenant=ser

  10. Swift调用OC和C

    Swift文件:main.swiftOC文件:Root.hRoot.mC函数文件:Fun.c桥接文件:工程名称-Bridging-Header.h

随机推荐

  1. 在airgapped(离线)CentOS 6系统上安装yum软件包

    我有一个CentOS6系统,出于安全考虑,它已经被空气泄漏.它可能从未连接到互联网,如果有,它很长时间没有更新.我想将所有.rpm软件包放在一个驱动器上,这样它们就可以脱机安装而无需查询互联网.但是,我在测试VM上遇到的问题是,即使指定了本地路径,yum仍然会挂起并尝试从在线存储库进行更新.另外,有没有办法使用yum-utils/yumdownloader轻松获取该包的所有依赖项和所有依赖项?目前

  2. centos – 命名在日志旋转后停止记录到rsyslog

    CentOS6.2,绑定9.7.3,rsyslog4.6.2我最近设置了一个服务器,我注意到在日志轮换后,named已停止记录到/var/log/messages.我认为这很奇怪,因为所有日志记录都是通过rsyslog进行的,并且named不会直接写入日志文件.这更奇怪,因为我在更新区域文件后命名了HUPed,但它仍然没有记录.在我停止并重新启动命名后,记录恢复.这里发生了什么?

  3. centos – 显示错误的磁盘大小

    对于其中一个磁盘,Df-h在我的服务器上显示错误的空白区域:Cpanel表明它只有34GB免费,但还有更多.几分钟前,我删除了超过80GB的日志文件.所以,我确信它完全错了.fdisk-l/dev/sda2也显示错误:如果没有格式化,我该怎么做才能解决这个问题?并且打开文件描述符就是它需要使用才能做到这一点.所以…使用“lsof”并查找已删除的文件.重新启动写入日志文件的服务,你很可能会看到空间可用.

  4. 如何在centos 6.9上安装docker-ce 17?

    我目前正在尝试在centOS6.9服务器上安装docker-ce17,但是,当运行yuminstalldocker-ce时,我收到以下错误:如果我用跳过的标志运行它我仍然得到相同的消息,有没有人知道这方面的方法?

  5. centos – 闲置工作站的异常负载平均值

    我有一个新的工作站,具有不寻常的高负载平均值.机器规格是:>至强cpu>256GB的RAM>4x512GBSSD连接到LSI2108RAID控制器我从livecd安装了CentOS6.564位,配置了分区,网络,用户/组,并安装了一些软件,如开发工具和MATLAB.在启动几分钟后,工作站负载平均值的值介于0.5到0.9之间.但它没有做任何事情.因此我无法理解为什么负载平均值如此之高.你能帮我诊断一下这个问题吗?

  6. centos – Cryptsetup luks – 检查内核是否支持aes-xts-plain64密码

    我在CentOS5上使用cryptsetupluks加密加密了一堆硬盘.一切都很好,直到我将系统升级到CentOS6.现在我再也无法安装磁盘了.使用我的关键短语装载:我收到此错误:在/var/log/messages中:有关如何装载的任何想法?找到解决方案问题是驱动器使用大约512个字符长的交互式关键短语加密.出于某种原因,CentOS6中的新内核模块在由旧版本创建时无法正确读取512个字符的加密密钥.似乎只会影响内核或cryptsetup的不同版本,因为在同一系统上创建和打开时,512字符的密钥将起作用

  7. centos – 大量ssh登录尝试

    22个我今天登录CentOS盒找到以下内容这是过去3天内的11次登录尝试.WTF?请注意,这是我从我的提供商处获得的全新IP,该盒子是全新的.我还没有发布任何关于此框的内容.为什么我会进行如此大量的登录尝试?是某种IP/端口扫描?基本上有4名匪徒,其中2名来自中国,1名来自香港,1名来自Verizon.这只发生在SSH上.HTTP上没有问题.我应该将罪魁祸首子网路由吗?你们有什么建议?

  8. centos – kswap使用100%的CPU,即使有100GB的RAM也可用

    >Linux内核是否应该足够智能,只需从内存中清除旧缓存页而不是启动kswap?

  9. centos – Azure将VM从A2 / 3调整为DS2 v2

    我正在尝试调整前一段时间创建的几个AzureVM,从基本的A3和标准A3到标准的DS2v2.我似乎没有能力调整到这个大小的VM.必须从头开始重建服务器会有点痛苦.如果它有所不同我在VM中运行CentOS,每个都有一个带有应用程序和操作系统的磁盘.任何人都可以告诉我是否可以在不删除磁盘的情况下删除VM,创建新VM然后将磁盘附加到新VM?

  10. centos – 广泛使用RAM时服务器计算速度减慢

    我在非常具体的情况下遇到服务器速度下降的问题.事实是:>1)我使用计算应用WRF>2)我使用双XeonE5-2620v3和128GBRAM(NUMA架构–可能与问题有关!

返回
顶部