10.1 基于commit命令创建

时间 : 16-03-28 栏目 : linux精讲 作者 : 老薛 评论 : 0 点击 : 2,168 次

Docker提供了docker commit命令,支持用户提交自己对容器的修改,并生成新的镜像。命令格式为docker  commit CONTAINER [REPOSITORY [:TAG]].
    这里将介绍如何使用docker commit命令,为ubuntu;14.04镜像添加SSH服务。
准备工作
首先,使用ubuntu:14.04镜像来创建一个容器:
[root@minion ~]# docker run -it ubuntu:14.04 /bin/bash 
Unable to find image 'ubuntu:14.04' locally
ab035c88d533: Download complete 
808ef855e5b6: Download complete 
267903aa9bd1: Download complete 
d28d8a6a946d: Download complete 
Status: Downloaded newer image for docker.io/ubuntu:14.04尝试使用SSHD命令,读者会发现容器中并没有安装该服务:
root@dc3cefc9587b:/# sshd
bash: sshd: command not found
安装和配置SSH服务
    更新软件包缓存后,已经可以安装SSH服务了,选择主流的openssh-server作为服务端。可以看到需要下载安装众多的依赖软件包:
root@dc3cefc9587b:/# apt-get install openssh-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  ca-certificates krb5-locales libck-connector0 libedit2 libgssapi-krb5-2
  libidn11 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib libwrap0 libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 ncurses-term
  openssh-client openssh-sftp-server openssl python python-chardet
  python-minimal python-requests python-six python-urllib3 python2.7
  python2.7-minimal ssh-import-id tcpd wget xauth
Suggested packages:
  krb5-doc krb5-user ssh-askpass libpam-ssh keychain monkeysphere rssh
  molly-guard ufw python-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
  ca-certificates krb5-locales libck-connector0 libedit2 libgssapi-krb5-2
  libidn11 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib libwrap0 libx11-6
  libx11-data libxau6 libxcb1 libxdmcp6 libxext6 libxmuu1 ncurses-term
  openssh-client openssh-server openssh-sftp-server openssl python
  python-chardet python-minimal python-requests python-six python-urllib3
  python2.7 python2.7-minimal ssh-import-id tcpd wget xauth
0 upgraded, 38 newly installed, 0 to remove and 0 not upgraded.
Need to get 7599 kB of archives.
After this operation, 35.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu/ trusty/main libedit2 amd64 3.1-20130712-2 [86.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu/ trusty/main libkrb5support0 amd64 1.12+dfsg-2ubuntu4 [29.5 kB]
Get:3 http://archive.ubuntu.com/ubuntu/ trusty/main libk5crypto3 amd64 1.12+dfsg-2ubuntu4 [79.5 kB]
Get:4 http://archive.ubuntu.com/ubuntu/ trusty/main libkeyutils1 amd64 1.5.6-1 [7318 B]
Get:5 http://archive.ubuntu.com/ubuntu/ trusty/main libkrb5-3 amd64 1.12+dfsg-2ubuntu4 [262 kB]
Get:6 http://archive.ubuntu.com/ubuntu/ trusty/main libgssapi-krb5-2 amd64 1.12+dfsg-2ubuntu4 [113 kB]
Get:7 http://archive.ubuntu.com/ubuntu/ trusty/main libidn11 amd64 1.28-1ubuntu2 [93.0 kB]
Get:8 http://archive.ubuntu.com/ubuntu/ trusty/main libxau6 amd64 1:1.0.8-1 [8376 B]
Get:9 http://archive.ubuntu.com/ubuntu/ trusty/main libxdmcp6 amd64 1:1.1.1-1 [12.8 kB]
Get:10 http://archive.ubuntu.com/ubuntu/ trusty/main libxcb1 amd64 1.10-2ubuntu1 [38.0 kB]
Get:11 http://archive.ubuntu.com/ubuntu/ trusty/main libx11-data all 2:1.6.2-1ubuntu2 [111 kB]
Get:12 http://archive.ubuntu.com/ubuntu/ trusty/main libx11-6 amd64 2:1.6.2-1ubuntu2 [560 kB]
Get:13 http://archive.ubuntu.com/ubuntu/ trusty/main libxext6 amd64 2:1.3.2-1 [33.9 kB]
Get:14 http://archive.ubuntu.com/ubuntu/ trusty/main libxmuu1 amd64 2:1.1.1-1 [11.0 kB]
Get:15 http://archive.ubuntu.com/ubuntu/ trusty/main libck-connector0 amd64 0.4.5-3.1ubuntu2 [10.5 kB]
Get:16 http://archive.ubuntu.com/ubuntu/ trusty/main libwrap0 amd64 7.6.q-25 [46.2 kB]
Get:17 http://archive.ubuntu.com/ubuntu/ trusty/main libpython2.7-minimal amd64 2.7.6-8 [307 kB]
Get:18 http://archive.ubuntu.com/ubuntu/ trusty/main python2.7-minimal amd64 2.7.6-8 [1190 kB]
Get:19 http://archive.ubuntu.com/ubuntu/ trusty/main openssl amd64 1.0.1f-1ubuntu2 [489 kB]
Get:20 http://archive.ubuntu.com/ubuntu/ trusty/main ca-certificates all 20130906ubuntu2 [175 kB]
Get:21 http://archive.ubuntu.com/ubuntu/ trusty/main krb5-locales all 1.12+dfsg-2ubuntu4 [12.3 kB]
Get:22 http://archive.ubuntu.com/ubuntu/ trusty/main openssh-client amd64 1:6.6p1-2ubuntu1 [566 kB]
Get:23 http://archive.ubuntu.com/ubuntu/ trusty/main wget amd64 1.15-1ubuntu1 [270 kB]
Get:24 http://archive.ubuntu.com/ubuntu/ trusty/main xauth amd64 1:1.0.7-1ubuntu1 [25.8 kB]
Get:25 http://archive.ubuntu.com/ubuntu/ trusty/main libpython2.7-stdlib amd64 2.7.6-8 [1872 kB]
Get:26 http://archive.ubuntu.com/ubuntu/ trusty/main libpython-stdlib amd64 2.7.5-5ubuntu3 [7012 B]
Get:27 http://archive.ubuntu.com/ubuntu/ trusty/main ncurses-term all 5.9+20140118-1ubuntu1 [243 kB]
Get:28 http://archive.ubuntu.com/ubuntu/ trusty/main openssh-sftp-server amd64 1:6.6p1-2ubuntu1 [34.1 kB]
Get:29 http://archive.ubuntu.com/ubuntu/ trusty/main openssh-server amd64 1:6.6p1-2ubuntu1 [319 kB]
Get:30 http://archive.ubuntu.com/ubuntu/ trusty/main python2.7 amd64 2.7.6-8 [197 kB]
Get:31 http://archive.ubuntu.com/ubuntu/ trusty/main python-minimal amd64 2.7.5-5ubuntu3 [27.5 kB]
Get:32 http://archive.ubuntu.com/ubuntu/ trusty/main python amd64 2.7.5-5ubuntu3 [134 kB]
Get:33 http://archive.ubuntu.com/ubuntu/ trusty/main python-chardet all 2.0.1-2build2 [106 kB]
Get:34 http://archive.ubuntu.com/ubuntu/ trusty/main python-six all 1.5.2-1 [8060 B]
Get:35 http://archive.ubuntu.com/ubuntu/ trusty/main python-urllib3 all 1.7.1-1build1 [38.9 kB]
Get:36 http://archive.ubuntu.com/ubuntu/ trusty/main python-requests all 2.2.1-1 [42.5 kB]
Get:37 http://archive.ubuntu.com/ubuntu/ trusty/main tcpd amd64 7.6.q-25 [23.0 kB]
Get:38 http://archive.ubuntu.com/ubuntu/ trusty/main ssh-import-id all 3.21-0ubuntu1 [9624 B]
Fetched 7599 kB in 26s (286 kB/s)                                              
Extracting templates from packages: 100%
Preconfiguring packages ...
Selecting previously unselected package libedit2:amd64.
(Reading database ... 11542 files and directories currently installed.)
Preparing to unpack .../libedit2_3.1-20130712-2_amd64.deb ...
Unpacking libedit2:amd64 (3.1-20130712-2) ...
Selecting previously unselected package libkrb5support0:amd64.
Preparing to unpack .../libkrb5support0_1.12+dfsg-2ubuntu4_amd64.deb ...
Unpacking libkrb5support0:amd64 (1.12+dfsg-2ubuntu4) ...
Selecting previously unselected package libk5crypto3:amd64.
Preparing to unpack .../libk5crypto3_1.12+dfsg-2ubuntu4_amd64.deb ...
Unpacking libk5crypto3:amd64 (1.12+dfsg-2ubuntu4) ...
Selecting previously unselected package libkeyutils1:amd64.
Preparing to unpack .../libkeyutils1_1.5.6-1_amd64.deb ...
Unpacking libkeyutils1:amd64 (1.5.6-1) ...
Selecting previously unselected package libkrb5-3:amd64.
Preparing to unpack .../libkrb5-3_1.12+dfsg-2ubuntu4_amd64.deb ...
Unpacking libkrb5-3:amd64 (1.12+dfsg-2ubuntu4) ...
Selecting previously unselected package libgssapi-krb5-2:amd64.
Preparing to unpack .../libgssapi-krb5-2_1.12+dfsg-2ubuntu4_amd64.deb ...
Unpacking libgssapi-krb5-2:amd64 (1.12+dfsg-2ubuntu4) ...
Selecting previously unselected package libidn11:amd64.
Preparing to unpack .../libidn11_1.28-1ubuntu2_amd64.deb ...
Unpacking libidn11:amd64 (1.28-1ubuntu2) ...
Selecting previously unselected package libxau6:amd64.
Preparing to unpack .../libxau6_1%3a1.0.8-1_amd64.deb ...
Unpacking libxau6:amd64 (1:1.0.8-1) ...
Selecting previously unselected package libxdmcp6:amd64.
Preparing to unpack .../libxdmcp6_1%3a1.1.1-1_amd64.deb ...
Unpacking libxdmcp6:amd64 (1:1.1.1-1) ...
Selecting previously unselected package libxcb1:amd64.
Preparing to unpack .../libxcb1_1.10-2ubuntu1_amd64.deb ...
Unpacking libxcb1:amd64 (1.10-2ubuntu1) ...
Selecting previously unselected package libx11-data.
Preparing to unpack .../libx11-data_2%3a1.6.2-1ubuntu2_all.deb ...
Unpacking libx11-data (2:1.6.2-1ubuntu2) ...
Selecting previously unselected package libx11-6:amd64.
Preparing to unpack .../libx11-6_2%3a1.6.2-1ubuntu2_amd64.deb ...
Unpacking libx11-6:amd64 (2:1.6.2-1ubuntu2) ...
Selecting previously unselected package libxext6:amd64.
Preparing to unpack .../libxext6_2%3a1.3.2-1_amd64.deb ...
Unpacking libxext6:amd64 (2:1.3.2-1) ...
Selecting previously unselected package libxmuu1:amd64.
Preparing to unpack .../libxmuu1_2%3a1.1.1-1_amd64.deb ...
Unpacking libxmuu1:amd64 (2:1.1.1-1) ...
Selecting previously unselected package libck-connector0:amd64.
Preparing to unpack .../libck-connector0_0.4.5-3.1ubuntu2_amd64.deb ...
Unpacking libck-connector0:amd64 (0.4.5-3.1ubuntu2) ...
Selecting previously unselected package libwrap0:amd64.
Preparing to unpack .../libwrap0_7.6.q-25_amd64.deb ...
Unpacking libwrap0:amd64 (7.6.q-25) ...
Selecting previously unselected package libpython2.7-minimal:amd64.
Preparing to unpack .../libpython2.7-minimal_2.7.6-8_amd64.deb ...
Unpacking libpython2.7-minimal:amd64 (2.7.6-8) ...
Selecting previously unselected package python2.7-minimal.
Preparing to unpack .../python2.7-minimal_2.7.6-8_amd64.deb ...
Unpacking python2.7-minimal (2.7.6-8) ...
Selecting previously unselected package openssl.
Preparing to unpack .../openssl_1.0.1f-1ubuntu2_amd64.deb ...
Unpacking openssl (1.0.1f-1ubuntu2) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20130906ubuntu2_all.deb ...
Unpacking ca-certificates (20130906ubuntu2) ...
Selecting previously unselected package krb5-locales.
Preparing to unpack .../krb5-locales_1.12+dfsg-2ubuntu4_all.deb ...
Unpacking krb5-locales (1.12+dfsg-2ubuntu4) ...
Selecting previously unselected package openssh-client.
Preparing to unpack .../openssh-client_1%3a6.6p1-2ubuntu1_amd64.deb ...
Unpacking openssh-client (1:6.6p1-2ubuntu1) ...
Selecting previously unselected package wget.
Preparing to unpack .../wget_1.15-1ubuntu1_amd64.deb ...
Unpacking wget (1.15-1ubuntu1) ...
Selecting previously unselected package xauth.
Preparing to unpack .../xauth_1%3a1.0.7-1ubuntu1_amd64.deb ...
Unpacking xauth (1:1.0.7-1ubuntu1) ...
Selecting previously unselected package libpython2.7-stdlib:amd64.
Preparing to unpack .../libpython2.7-stdlib_2.7.6-8_amd64.deb ...
Unpacking libpython2.7-stdlib:amd64 (2.7.6-8) ...
Selecting previously unselected package libpython-stdlib:amd64.
Preparing to unpack .../libpython-stdlib_2.7.5-5ubuntu3_amd64.deb ...
Unpacking libpython-stdlib:amd64 (2.7.5-5ubuntu3) ...
Selecting previously unselected package ncurses-term.
Preparing to unpack .../ncurses-term_5.9+20140118-1ubuntu1_all.deb ...
Unpacking ncurses-term (5.9+20140118-1ubuntu1) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a6.6p1-2ubuntu1_amd64.deb ...
Unpacking openssh-sftp-server (1:6.6p1-2ubuntu1) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a6.6p1-2ubuntu1_amd64.deb ...
Unpacking openssh-server (1:6.6p1-2ubuntu1) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../python2.7_2.7.6-8_amd64.deb ...
Unpacking python2.7 (2.7.6-8) ...
Selecting previously unselected package python-minimal.
Preparing to unpack .../python-minimal_2.7.5-5ubuntu3_amd64.deb ...
Unpacking python-minimal (2.7.5-5ubuntu3) ...
Selecting previously unselected package python.
Preparing to unpack .../python_2.7.5-5ubuntu3_amd64.deb ...
Unpacking python (2.7.5-5ubuntu3) ...
Selecting previously unselected package python-chardet.
Preparing to unpack .../python-chardet_2.0.1-2build2_all.deb ...
Unpacking python-chardet (2.0.1-2build2) ...
Selecting previously unselected package python-six.
Preparing to unpack .../python-six_1.5.2-1_all.deb ...
Unpacking python-six (1.5.2-1) ...
Selecting previously unselected package python-urllib3.
Preparing to unpack .../python-urllib3_1.7.1-1build1_all.deb ...
Unpacking python-urllib3 (1.7.1-1build1) ...
Selecting previously unselected package python-requests.
Preparing to unpack .../python-requests_2.2.1-1_all.deb ...
Unpacking python-requests (2.2.1-1) ...
Selecting previously unselected package tcpd.
Preparing to unpack .../tcpd_7.6.q-25_amd64.deb ...
Unpacking tcpd (7.6.q-25) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_3.21-0ubuntu1_all.deb ...
Unpacking ssh-import-id (3.21-0ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
Setting up libedit2:amd64 (3.1-20130712-2) ...
Setting up libkrb5support0:amd64 (1.12+dfsg-2ubuntu4) ...
Setting up libk5crypto3:amd64 (1.12+dfsg-2ubuntu4) ...
Setting up libkeyutils1:amd64 (1.5.6-1) ...
Setting up libkrb5-3:amd64 (1.12+dfsg-2ubuntu4) ...
Setting up libgssapi-krb5-2:amd64 (1.12+dfsg-2ubuntu4) ...
Setting up libidn11:amd64 (1.28-1ubuntu2) ...
Setting up libxau6:amd64 (1:1.0.8-1) ...
Setting up libxdmcp6:amd64 (1:1.1.1-1) ...
Setting up libxcb1:amd64 (1.10-2ubuntu1) ...
Setting up libx11-data (2:1.6.2-1ubuntu2) ...
Setting up libx11-6:amd64 (2:1.6.2-1ubuntu2) ...
Setting up libxext6:amd64 (2:1.3.2-1) ...
Setting up libxmuu1:amd64 (2:1.1.1-1) ...
Setting up libck-connector0:amd64 (0.4.5-3.1ubuntu2) ...
Setting up libwrap0:amd64 (7.6.q-25) ...
Setting up libpython2.7-minimal:amd64 (2.7.6-8) ...
Setting up python2.7-minimal (2.7.6-8) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up openssl (1.0.1f-1ubuntu2) ...
Setting up ca-certificates (20130906ubuntu2) ...
Setting up krb5-locales (1.12+dfsg-2ubuntu4) ...
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
 
deb http://archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://archive.ubuntu.com/ubuntu/ trusty main restricted
 
## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted
 
## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://archive.ubuntu.com/ubuntu/ trusty universe
deb http://archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://archive.ubuntu.com/ubuntu/ trusty-updates universe
 
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted
 
deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted
deb http://archive.ubuntu.com/ubuntu/ trusty-security universe
deb-src http://archive.ubuntu.com/ubuntu/ trusty-security universe
# deb http://archive.ubuntu.com/ubuntu/ trusty-security multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ trusty-security multiverse
Setting up openssh-client (1:6.6p1-2ubuntu1) ...
Setting up wget (1.15-1ubuntu1) ...
Setting up xauth (1:1.0.7-1ubuntu1) ...
Setting up libpython2.7-stdlib:amd64 (2.7.6-8) ...
Setting up libpython-stdlib:amd64 (2.7.5-5ubuntu3) ...
Setting up ncurses-term (5.9+20140118-1ubuntu1) ...
Setting up openssh-sftp-server (1:6.6p1-2ubuntu1) ...
Setting up openssh-server (1:6.6p1-2ubuntu1) ...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
Creating SSH2 ED25519 key; this may take some time ...
invoke-rc.d: policy-rc.d denied execution of start.
Setting up python2.7 (2.7.6-8) ...
Setting up python-minimal (2.7.5-5ubuntu3) ...
Setting up python (2.7.5-5ubuntu3) ...
Setting up python-chardet (2.0.1-2build2) ...
Setting up python-six (1.5.2-1) ...
Setting up python-urllib3 (1.7.1-1build1) ...
Setting up python-requests (2.2.1-1) ...
Setting up tcpd (7.6.q-25) ...
Setting up ssh-import-id (3.21-0ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
Processing triggers for ca-certificates (20130906ubuntu2) ...
Updating certificates in /etc/ssl/certs... 164 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d....done.
Processing triggers for ureadahead (0.100.0-16) ...
要正常启动SSH服务,需要目录/var/run/ssh存在,手动创建它,并启动服务:
root@dc3cefc9587b:/# mkdir -p /var/run/sshd
root@dc3cefc9587b:/# /usr/sbin/sshd -D &   
[1] 3237
此时查看容器的22端口(SSH服务默认监听的端口),已经处于监听状态:
root@dc3cefc9587b:/# netstat -tunlp
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      3237/sshd       
tcp6       0      0 :::22                   :::*                    LISTEN      3237/sshd
修改SSH服务的安全登录配置,取消pam登录限制:
root@dc3cefc9587b:/# sed -ri 's/session    required     pam_loginuid.so/#session    required     pam_loginuid.so/g' /etc/pam.d/sshd
root用户目录下创建.ssh目录,并复制需要登录的公钥信息(一般为本地主机用户目录下的.ssh/id_rsa.pub文件,可由ssh-keygen -t  rsa命令生成)到authorized_keys文件中。
root@dc3cefc9587b:/# mkdir root/.ssh
root@dc3cefc9587b:/# vi /root/.ssh/authorized_keys
创建自动启动SSH服务的可执行文件run.sh,并添加可执行权限:
root@dc3cefc9587b:/# vi /run.sh
root@dc3cefc9587b:/# chmod +x run.sh
run.sh脚本内容如下:
#/bin/bash
/usr/sbin/sshd -D
最后,退出容器:
root@dc3cefc9587b:/# exit
exit
保存镜像
    将所退出的容器用docker commit命令保存为一个新的sshd:ubuntu镜像:
[root@minion ~]# docker commit dc3cefc9587b sshd:ubuntu
4e60c2b946076d8cefda8c24075f0e86c492f776a9c14af2b465a182db82ac42
使用docker images查看本地生成的新镜像sshdubuntu,目前拥有的镜像如下:
[root@minion ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED              VIRTUAL SIZE
sshd                          ubuntu              4e60c2b94607        About a minute ago   229.9 MB
docker.io/ubuntu              14.04               ab035c88d533        5 days ago           187.9 MB
docker.io/busybox             latest              f1e4b055fb65        7 days ago           1.113 MB
docker.io/centos              latest              bb3d629a7cbc        2 weeks ago          196.6 MB
172.17.0.1:5000/centos5       latest              275c8487cd76        2 weeks ago          245.1 MB
centos                        5                   275c8487cd76        2 weeks ago          245.1 MB
centos                        6                   3a2306cb3194        3 weeks ago          574.3 MB
<none>                        <none>              fef924a0204a        5 weeks ago          1.114 MB
docker.io/registry            latest              07d93e41c370        8 weeks ago          422.8 MB
docker.io/centos              centos6.7           3fba1048142f        5 months ago         190.6 MB
docker.io/training/webapp     latest              02a8815912ca        10 months ago        348.7 MB
docker.io/training/postgres   latest              258105bea10d        21 months ago        364.6 MB
使用镜像
    启动容器,并添加端口映射10022-->22。其中10022是宿主机的端口,22是容器的SSH服务监听端口:
[root@minion ~]# docker run -p 10022:22 -d sshd:ubuntu /run.sh
2f29560c196465a91de947ea902d02dc2f5f5c6f5153197f91523b4d9b9a3ca6
启动成功后,可以在宿主机上看到容器运行的详细信息:
[root@minion ~]# docker ps
在宿主机(172.17.42.1)或其他主机上,可以通过SSH访问10022端口来登录容器:
ssh 172.17.42.1 -p 10022

本文标签

除非注明,文章均为( 老薛 )原创,转载请保留链接: http://www.bdkyr.com/operation/1489.html

随便看看

0