mac-docker-note mac使用docker搭建php nginx

Docker 是个伟大的项目,它彻底释放了虚拟化的威力,极大降低了云计算资源供应的成本,同时让应用的分发、测试、部署和分发都变得前所未有的高效和轻松!

下载安装boot2docker
https://github.com/boot2docker/osx-installer/releases
安装参考官方文档:
http://docs.docker.com/installation/mac/
在Launchpad中启动boot2docker
检查docker是否安装成功,运行hello-world容器:

1
docker run hello-world

Start an NGINX container on the DOCKER_HOST.
在docker的宿主机上启动一个nginx容器

1
docker run -d -p 80:80 -P --name web nginx -v //nginx.conf:/etc/nginx/nginx.conf:ro

The -d flag keeps the container running in the background after the docker run command completes.
d:代表在后台运行

容器的操作

1
2
3
4
$ docker start web #启动容器名为web的容器
$ docker exec -it web bash #进入容器
$ docker stop web #停止容器
$ docker rm web #删除容器

保存容器至镜像

docker commit -m “new nginx” -a “gang” web gang/nginx:v1
docker commit -m “my new php-fpm images” -a “gang” php-fpm-ct gang/php-fpm:v1

docker run —name nginx-ct -d -p 80:80 -v /Users/gang/work/:/usr/share/nginx/html gang/nginx:v1

docker run —name php-fpm-ct -d -p 9000:9000 -v /Users/work:/var/www/html gang/php-fpm:v1

nginx配置文件修改

location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 192.168.59.103:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}

镜像的操作

1
2
$ docker images
$ docker rmi ad673a791d21 # 删除images

显示docker的ip

boot2docker ip

默认的nginx容器没有vim

这是为了让容器保持最小化
cat /etc/nginx/conf.d/root /usr/share/nginx/html

安装php-fpm

docker run —name php-fpm-ct -d -p 9000:9000 -v /local/dir:/var/www/html php:5.6-fpm

docker官方提供的image

https://registry.hub.docker.com/repos/library/

其他参考资料

http://dockerpool.com/static/books/docker_practice/appendix_repo/nginx.html