docker安裝nginx+php7+mysql+redis
阿新 • • 發佈:2019-01-03
1、下載映象
#docker pull nginx
#docker pull php:7.1.0-fpm
2、建立docker對映目錄
#mkdir -p /docker/www
#mkdir -p /docker/nginx/conf.d
3、編輯nginx配置檔案
#vim /docker/nginx/conf.d/default.conf # 以下為示例內容 server { listen 80 default_server; server_name _; root /usr/share/nginx/html; location / { index index.html index.htm index.php; try_files $uri $uri/ /index.php$is_args$query_string; autoindex off; } location ~ \.php(.*)$ { root /var/www/html/; fastcgi_pass 172.17.0.2:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } }
4、啟動PHP映象
docker run -p 9000:9000 --name myphp -v /docker/www/:/var/www/html/ --privileged=true -d php:7.1.0-fpm #檢視php映象的ip地址 docker inspect --format='{{.NetworkSettings.IPAddress}}' myphp 172.17.0.2 #修改default.conf配置檔案,使fastcgi_pass的值為 172.17.0.2:9000 vi /docker/nginx/conf.d/default.conf fastcgi_pass 172.17.0.2:9000;
5、啟動nginx映象
docker run -p 80:80 --name mynginx -v /docker/www:/usr/share/nginx/html -v /docker/nginx/conf.d:/etc/nginx/conf.d --privileged=true -d nginx
6、測試Nginx和php是否正常
echo "test" > /docker/www/index.html
echo "<?php echo phpinfo();" > /docker/www/info.php
#使用IP地址或域名訪問看是否顯示正常
說明:docker 啟動是使用一個或多個 -v 引數,使容器內的目錄對映到宿主機上,每次修改不必進入宿主機操作
7、mysql 和redis/memcached等涉及資料儲存的應用不安裝docker容器內,防止容器刪除資料丟失
mysql
#sudo apt-get install mysql-server
#sudo apt isntall mysql-client
redis
#sudo apt-get install redis-server
#sudo service redis-server start
8、php docker容器安裝php相應的拓展
#docker-php-ext-install bcmath dba exif mysqli pdo_mysql sysvsem sysvshm pdo_mysql
#驗證
#php -m | grep -i 'mysql'