1查看当前有的镜像
[root@docker-01 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos6.9_ssh v1.0 dcfb31f8f318 4 hours ago 304MB
centos 6.9 e88c611d16a0 7 months ago 195MB
nginx latest be1f31be9a87 7 months ago 109MB
2创建一个并运行一个容器
[root@docker-01 ~]# docker run -d -p 1023:22 -p 80:80 centos6.9_ssh:v1.0 /usr/sbin/sshd -D
630598d045766097cb496c2e94c0b1587031da79549be6161797917618d1be97
3ssh登录容器
[root@docker-01 ~]# ssh 10.0.0.11 -p 1023
root@10.0.0.11's password:
[root@630598d04576 ~]#
4环境部署
[root@630598d04576 ~]# yum install -y httpd php php-fpm mysql mysql-server php-mysql vim unzip
[root@630598d04576 ~]# mkdir -p /server/scripts
[root@630598d04576 ~]# cd /server/scripts
[root@630598d04576 scripts]# vim startme.sh
#!/bin/bash
service httpd start
service mysqld start
service php-fpm start
/usr/sbin/sshd -D
[root@630598d04576 scripts]# chmod +x startme.sh
[root@630598d04576 scripts]# service httpd start
[root@630598d04576 scripts]# service mysqld start
[root@630598d04576 scripts]# service php-fpm start
4环境测试
[root@630598d04576 scripts]# cd /var/www/html
[root@630598d04576 html]# vim test.php
<?php
echo "<title>Test Page</title>";
phpinfo()
?>
4.1 浏览器测试
出现PHP的测试页面,至此完成了项目的80%.
5 数据库操作
mysqladmin -u root password "123"
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
6 上传discuz代码
##宿主机操作
[root@docker-01 wyf]# docker cp -a Discuz_X3.4_SC_UTF8_0802.zip 630598d04576:/var/www/html
##容器操作
unzip Discuz_X3.4_SC_UTF8_0802.zip
cd upload/
mv ./* ../
cd ..
chmod -R 777 /var/www/html
7查看代码连接数据库
[root@630598d04576 html]# cat utility/convert/data/config.default.php
<?php
/**
* DiscuzX Convert
*
* $Id: index.php 8 2010-04-07 03:56:45Z Cnteacher $
*/
$_config['source']['dbhost'] = 'localhost';
$_config['source']['dbuser'] = 'root';
$_config['source']['dbpw'] = '';
$_config['source']['dbname'] = 'discuz';
$_config['source']['tablepre'] = 'cdb_';
$_config['source']['dbcharset'] = '';
$_config['source']['pconnect'] = '1';
$_config['target']['dbhost'] = 'localhost';
$_config['target']['dbuser'] = 'root';
$_config['target']['dbpw'] = '';
$_config['target']['dbname'] = 'discuzx';
$_config['target']['tablepre'] = 'pre_';
$_config['target']['dbcharset'] = '';
$_config['target']['pconnect'] = '1';
$_config['ucenter']['dbhost'] = '';
$_config['ucenter']['dbuser'] = '';
$_config['ucenter']['dbpw'] = '';
$_config['ucenter']['dbname'] = '';
$_config['ucenter']['tablepre'] = '';
$_config['ucenter']['dbcharset'] = '';
$_config['ucenter']['pconnect'] = '1';
?>[root@630598d04576 html]#
8 浏览器安装
至此项目安装成功
9将容器提交为镜像
容器执行 Ctrl+D
2.宿主机执行命令:
[root@docker-01 wyf]# docker commit 422ac662c9eb centos_discuz:v1.1
sha256:d141aa30489d5f9b2f15afbc331eb688ccef3de276e8c7dcba7dc0cc495ffb2b
[root@docker-01 wyf]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos_discuz v1.1 d141aa30489d 12 seconds ago 547MB
centos6.9_discuz v1 ee967b1fa8ec About an hour ago 541MB
centos6.9_ssh v1.0 dcfb31f8f318 5 hours ago 304MB
centos 6.9 e88c611d16a0 7 months ago 195MB
nginx latest be1f31be9a87 7 months ago 109MB
10 镜像测试
10.1 基于提交的镜像创建并运行一个镜像
[root@docker-01 wyf]# docker rm -f `docker ps -a -q`
422ac662c9eb
[root@docker-01 wyf]# docker run -d -p 1022:22 -p 80:80 centos_discuz:v1.1 sh /server/scripts/startme.sh
bcd34c7f126c2dcdff33843d2874d06ba34eb4cc244a313caae99628c8a2d8dd
[root@docker-01 wyf]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bcd34c7f126c centos_discuz:v1.1 "sh /server/scripts/…" 9 seconds ago Up 8 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:1022->22/tcp amazing_engelbart
[root@docker-01 wyf]#