下载安装boot2docker
https://github.com/boot2docker/osx-installer/releases
安装参考官方文档:
http://docs.docker.com/installation/mac/
在Launchpad中启动boot2docker
检查docker是否安装成功,运行hello-world容器:
docker run hello-world
Start an NGINX container on the DOCKER_HOST.
在docker的宿主机上启动一个nginx容器
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:代表在后台运行
容器的操作
$ 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 -p 11211:11211 -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;
}
镜像的操作
$ 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
给容器 php-fpm-ct安装php扩展libmemcached遇见问题
apt-get install libmemcached提示有依赖包没安装,也没说是什么包。尝试google答案未果,尝试更新下/etc/apt/source.list
cat /etc/issue # 查看Linux版本
Debian GNU/Linux 8
或者uname -a
或者cat /proc/version
apt-get dselect-upgrade
通过dselect的“建议”和“推荐”功能更新系统。dselect是Debian中一个功能强大的包管理工具。它可帮助用户选择软件包来安装,其中一个有用功能是它会建议和推荐安装其它相关软件包。我们可在APT中使用它这个功能。
apt-get install aptitude
解决办法2,可以选择ubuntu版本的Linux,不用debian的
apt-get install libmemcached-dev
cd /var/www/html/memcached-2.2.0
phpzie
./configure --enable-memcached --with-php-config=/usr/local/bin/php-config -with-zlib-dir
/bin/bash /var/www/html/memcached-2.2.0/libtool --mode=install cp ./memcached.la /var/www/html/memcached-2.2.0/modules
cp ./.libs/memcached.so /var/www/html/memcached-2.2.0/modules/memcached.so
cp ./.libs/memcached.lai /var/www/html/memcached-2.2.0/modules/memcached.la
PATH="$PATH:/sbin" ldconfig -n /var/www/html/memcached-2.2.0/modules
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20131226/
!!!之前没有了解到docker php-fpm-ct 容器的Linux版本用的是Debian,安装libmemcache在Debian中叫libmemcached-dev,而在Ubuntu中叫libmemcached
memcache操作
启动服务
etc/init.d/memcached -d -c 10240 -m 1024 -u root
之后就可用如下命令操作memcached服务
Usage: /etc/init.d/memcached {start|stop|restart|force-reload|status}
docker官方提供的image
https://registry.hub.docker.com/repos/library/
其他参考资料
http://dockerpool.com/static/books/docker_practice/appendix_repo/nginx.html
网友评论