目标: 制作一个承载apache的镜像,并在一个Linux内启动5个apache容器对外提供服务
1、安装apache
docker run -t -i --name=qxy_apache centos
yum -y install httpd
exit
2、制作镜像
docker commit qxy_apache qxy_apache:v1.0
[root@centos-1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
qxy_apache v1.0 9b6f8b6054b5 34 seconds ago 196.6 MB
3、创建容器
docker run --name=apache_8001 -d -t -i -p 8001:80 -v /root/httpd/httpd_8001:/var/www/html qxy_apache
docker run --name=apache_8002 -d -t -i -p 8002:80 -v /root/httpd/httpd_8002:/var/www/html qxy_apache
docker run --name=apache_8003 -d -t -i -p 8003:80 -v /root/httpd/httpd_8003:/var/www/html qxy_apache
docker run --name=apache_8004 -d -t -i -p 8004:80 -v /root/httpd/httpd_8004:/var/www/html qxy_apache
docker run --name=apache_8005 -d -t -i -p 8005:80 -v /root/httpd/httpd_8005:/var/www/html qxy_apache
#这里 -d 为后台运行,方便批量执行;需要注意的是如果只有-d容器将无法启动
4、制作最简页面^_^
[root@centos-1 httpd]# cd /root/httpd
[root@centos-1 httpd]# for i in *
> do
> echo "hello "$i > ./$i/index.html
> done
[root@centos-1 httpd]# find . -type f | xargs cat
hello httpd_8001
hello httpd_8002
hello httpd_8003
hello httpd_8004
hello httpd_8005
5、启动httpd
[root@centos-1 httpd]# for i in `seq 1 5`
> do
> docker exec apache_800$i httpd -k start
> docker top apache_800$i
> done
6、检验apache
[root@centos-2 ~]# for i in `seq 1 5`
> do
> curl http://192.168.110.111:800$i > done
hello httpd_8001
hello httpd_8002
hello httpd_8003
hello httpd_8004
hello httpd_8005
(责任编辑:IT) |