创建支持SSH服务的镜像

一、基于commit命令创建

docker commit CONTAINER [REPOSITORY [:TAG]]

1、使用ubuntu镜像创建一个容器

docker run -it ubuntu /bin/bash

2、配置软件源

[email protected]:/# cp /etc/apt/sources.list /etc/apt/sources.list.bak
[email protected]:/# apt-get update
[email protected]:/# apt-get install vim
[email protected]:/# vim /etc/apt/sources.list //配置阿里云软件源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
[email protected]:/# apt-get update

3、安装和配置SSH服务

[email protected]:/# apt-get install openssh-server
[email protected]:/# mkdir -p /var/run/sshd
[email protected]:/# /usr/sbin/sshd -D &
[1] 4003
[email protected]:/# jobs
[1]+  Running                 /usr/sbin/sshd -D &
[email protected]:/# apt-get install net-tools
[email protected]:/# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      4003/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      4003/sshd
[email protected]:/# sed -ri ‘s/session    required     pam_loginuid.so/#session    required     pam_loginuid.so/g‘ /etc/pam.d/sshd
[email protected]:/# mkdir root/.ssh
[email protected]:/# vim root/.ssh/authorized_keys
[email protected]:/# vim /run.sh
#!/bin/bash
/usr/sbin/sshd -D
[email protected]:/# chmod +x /run.sh
[email protected]:/# exit

4、保存镜像

[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                     NAMES
8bfbf48c59f8        ubuntu              "/bin/bash"              51 minutes ago      Exited (0) 4 seconds ago                             reverent_lumiere
05c71189c30e        ubuntu              "/bin/bash"              4 hours ago         Exited (0) 4 hours ago                               wonderful_wright
387d42ee191b        busybox             "sh"                     5 hours ago         Exited (2) 5 hours ago                               priceless_wing
d91b7c33a198        training/webapp     "python app.py"          17 hours ago        Up 17 hours                0.0.0.0:32785->5000/tcp   web
7e17a1d0cb21        training/postgres   "su postgres -c ‘/..."   17 hours ago        Up 17 hours                5432/tcp                  db
[[email protected] ~]# docker commit 8bfb sshd:ubuntu
sha256:34aafa7f58cae9f55bab2183f0c14dcc065dcfd3cc772115808e9c30d1680889
[[email protected] ~]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED             SIZE
sshd                   ubuntu              34aafa7f58ca        6 seconds ago       263 MB
busybox                latest              c75bebcdd211        2 weeks ago         1.11 MB
haproxy                latest              c481d2544260        3 weeks ago         136 MB
liuyongsheng614/test   latest              c400af73564b        2 months ago        130 MB
test                   latest              c400af73564b        2 months ago        130 MB
ubuntu                 latest              0ef2e08ed3fa        3 months ago        130 MB
training/webapp        latest              6fae60ef3446        2 years ago         349 MB
training/postgres      latest              6fa973bb3c26        2 years ago         365 MB

5、使用镜像

[[email protected] ~]# docker run -d -p 10022:22 sshd:ubuntu /run.sh
d4ad0fcf769edf268854e7b5f1b0e62ed78a52b836cf3b2f4f1a97630835696e
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
d4ad0fcf769e        sshd:ubuntu         "/run.sh"                5 seconds ago       Up 3 seconds        0.0.0.0:10022->22/tcp     cranky_stonebraker
d91b7c33a198        training/webapp     "python app.py"          17 hours ago        Up 17 hours         0.0.0.0:32785->5000/tcp   web
7e17a1d0cb21        training/postgres   "su postgres -c ‘/..."   17 hours ago        Up 17 hours         5432/tcp                  db
[[email protected] ~]# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1416/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2037/master
tcp6       0      0 :::32785                :::*                    LISTEN      10359/docker-proxy
tcp6       0      0 :::22                   :::*                    LISTEN      1416/sshd
tcp6       0      0 :::10022                :::*                    LISTEN      20173/docker-proxy
[[email protected] ~]# ssh 192.168.20.107 -p 10022
The authenticity of host ‘[192.168.20.107]:10022 ([192.168.20.107]:10022)‘ can‘t be established.
ECDSA key fingerprint is c4:7d:d1:44:79:a2:7a:18:27:16:f7:55:47:ed:7c:e7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘[192.168.20.107]:10022‘ (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 3.10.0-514.10.2.el7.x86_64 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

[email protected]:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:04
          inet addr:172.17.0.4  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:47 errors:0 dropped:0 overruns:0 frame:0
          TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:7349 (7.3 KB)  TX bytes:6493 (6.4 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

二、使用Dockerfile创建

1、

时间: 2024-08-01 22:03:36

创建支持SSH服务的镜像的相关文章

Docker:使用Dockerfile创建支持SSH服务的镜像

1.创建工作目录 # mkdir sshd_ubuntu # ls 在其中,创建Dockerfile和run.sh文件 # cd sshd_ubuntu/ # touch Dockerfile run.sh # ls 2. 编写run.sh脚本和authorized_keys文件 # vi run.sh 写入内容: #! /bin/bash /usr/sbin/sshd –D 在宿主主机上生成SSH密钥对,并创建authorized_keys # ssh-keygen –t rsa # cat

docker基于Dockerfile命令创建支持ssh服务的镜像

首先,创建一个sshd_centos工作目录: [[email protected] ~]# mkdir sshd_centos [[email protected] ~]# cd sshd_centos [[email protected] sshd_centos]# touch Dockerfile run.sh [[email protected] sshd_centos]# ssh-keygen -t rsa [[email protected] sshd_centos]# cat ~/

Docker使用Dockerfile创建支持ssh服务自启动的容器镜像

1. 首先创建一个Dockerfile文件,文件内容如下 # 选择一个已有的os镜像作为基础 FROM centos:centos6 # 镜像的作者 MAINTAINER Fanbin Kong "[email protected]" # 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no RUN yum install -y openssh-server sudo RUN sed -i 's/UsePAM yes/UsePAM no/g' /

创建支持ssh的docker镜像

docker容器运行,一般不能ssh,这容器的管理带来麻烦,下面将介绍如何创建支持ssh的docker镜像 首先从dock hub  下载 ubuntu的镜像 命令: docker pull ubuntu 新建一个ssh_ubuntu 目录 mkdir /ssh_ubuntu cd /ssh_ubuntu ;touch Dockerfile vi Dockerfile Dockerfile内容 FROM ubuntu MAINTAINER lincoln_zhongRUN apt-get upd

创建支持ssh服务的docker容器和镜像

http://www.kongxx.info/blog/?p=57 1. 这里使用的centos作为容器,所以首先下载centos的imagessudo docker pull centos 2. 下载后运行一个centos的容器,这里使用centos6作为我测试的容器sudo docker run --name=centos-ssh -i -t centos:centos6 /bin/bash 3. 安装openssh-server服务软件包yum install openssh-server

Docker创建支持ssh服务的容器和镜像

Dockerfile 支持系统启动 运行ssh 服务 原文链接:http://blog.csdn.net/kongxx/article/details/38395305 # 选择一个已有的os镜像作为基础 FROM centos:centos6 # 镜像的作者 MAINTAINER Fanbin Kong "[email protected]" # 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no RUN yum install -y ope

docker创建支持ssh服务的centos镜像

以centos为基础,目的使用ssh服务远程连接docker容器 环境:宿主机centos7,直接搜索docker的centos镜像,下载最新版本 1.先按照docker:yum install -y epel-release yum install -y docker 2.启动docker: systemctl start docker.service 3.使用ps查看docker是否启动 ps aux |grep docker 4.下载centos的docker镜像 docker pull

用dockerfile创建支持ssh服务的centos镜像

参考 1 我在/docker/目录下建立了个脚本是用来启动容器上面的ssh服务的 vi run.sh #!/bin/bash /usr/sbin/sshd -D 2 同样在docker目录下创建dockefile文件如下: [[email protected] sbin]# cat /docker/dockerfile  FROM centos RUN yum install passwd openssl openssh-server -y ##下面三行是解决sshd服务启动时报错的 RUN s

Docker-创建支持ssh服务的镜像

这里测试tomcat镜像安装ssh服务 1.启动镜像 [[email protected] docker]$ docker run -d tomcat:centos 844bdde121a03174f3abd226a9ef286938b6ea4a1fbd2659961b1e8542ca3ccd [[email protected] docker]$ docker exec -it 844 /bin/bash [[email protected] /]# 2.安装ssh服务 [[email pro