操作环境
Centos 7
Docker version 17.03.0-ce, build 3a232c8
操作步骤
1.启动Centos6的Container
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6-httpd-new latest 8f49b55376bb 7 minutes ago 311 MB
centos6 ssh 98dd9dcf78e4 About an hour ago 325 MB
centos6-mysqld latest 02d4792b8784 2 days ago 396 MB
centos6-httpd latest 4a267ee811d7 2 days ago 311 MB
centos centos6 ae5cb7280ec3 8 days ago 195 MB
centos latest 98d35105a391 8 days ago 192 MB
registry latest 047218491f8c 2 weeks ago 33.2 MB
alpine latest 4a415e366388 2 weeks ago 3.98 MB
ubuntu latest 0ef2e08ed3fa 3 weeks ago 130 MB
hello-world latest 48b5124b2768 2 months ago 1.84 kB
shipyard/shipyard latest 36fb3dc0907d 5 months ago 58.8 MB
shipyard/rethinkdb latest 4841f0ad4547 21 months ago 296 MB
[root@localhost ~]# docker run -ti ae5cb7280ec3 /bin/bash
[root@c4a48484cdea /]# yum -y install openssh-server openssh-clients
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
/PermitRootLogin
设置root登录密码
[root@c4a48484cdea /]# passwd
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
4.安装nginx
[root@c4a48484cdea /]#yum -y install nginx
5.安装mysql
[root@c4a48484cdea /]#yum -y install mysql-server
6.制作包含ssh-server、mysql-server、nginx的image
[root@localhost ~]# docker commit c4a48484cdea centos6-ssh-nginx-mysql
sha256:9c3ac4d67e85108a22bf73597e5afaf2b8d0b1da1b0653c4a49b4f92784e32a5
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6-ssh-nginx-mysql latest 9c3ac4d67e85 17 seconds ago 1.08 GB
centos6-httpd-new latest 8f49b55376bb 20 minutes ago 311 MB
centos6 ssh 98dd9dcf78e4 About an hour ago 325 MB
centos6-mysqld latest 02d4792b8784 2 days ago 396 MB
centos6-httpd latest 4a267ee811d7 2 days ago 311 MB
centos centos6 ae5cb7280ec3 8 days ago 195 MB
centos latest 98d35105a391 8 days ago 192 MB
registry latest 047218491f8c 2 weeks ago 33.2 MB
alpine latest 4a415e366388 2 weeks ago 3.98 MB
ubuntu latest 0ef2e08ed3fa 3 weeks ago 130 MB
hello-world latest 48b5124b2768 2 months ago 1.84 kB
shipyard/shipyard latest 36fb3dc0907d 5 months ago 58.8 MB
shipyard/rethinkdb latest 4841f0ad4547 21 months ago 296 MB
[root@localhost ~]# docker run -ti -p 2201:22 -p 80:80 -p 3336:3306 45098a3e29fd /bin/bash
[root@bafd6bc07e28 /]# /etc/init.d/sshd start
Starting sshd: [ OK ]
[root@bafd6bc07e28 /]# /etc/init.d/nginx start
Starting nginx: [ OK ]
[root@bafd6bc07e28 /]# /etc/init.d/mysqld start
Starting mysqld: [ OK ]
8.验证ssh server,在宿主机通过ssh登录
[root@localhost ~]# ssh root@localhost -p 2201
The authenticity of host '[localhost]:2201 ([::1]:2201)' can't be established.
RSA key fingerprint is 0e:8c:a1:62:b7:00:80:f0:f8:52:4e:95:f9:49:7a:a6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2201' (RSA) to the list of known hosts.
root@localhost's password:
[root@bafd6bc07e28 ~]#
9.验证nginx
10.验证mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>