鏡像下載php
[root@localhost ~]# docker pull nginx
[root@localhost ~]# docker pull mysql
[root@localhost ~]# docker pull php:7.1.0-fpm
編寫生成nginx容器腳本html
[root@localhost ~]# vim docker_nginx.sh #!/usr/bin/env bash docker run -p 80:80 --name nginx \ -v /docker/code:/usr/share/nginx/html \ -v /var/log/nginx:/var/log/nginx \ -v /docker/nginx/conf.d:/etc/nginx/conf.d \ --privileged=true \ -d nginx [root@localhost ~]# sh docker_nginx.sh 3e9cd3d3b97c7e5ca001b30b5905c02c616fc48a81d14f716e3242d181ce2b31
編寫生成php容器腳本mysql
[root@localhost ~]# vim docker_php.sh #! /usr/bin bash docker run -p 9000:9000 --name php \ -v /docker/code/:/var/www/html/ \ --privileged=true \ -d php:7.1.0-fpm [root@localhost ~]# sh docker_php.sh 754a8c8c860fb3650a92e011ebae9d0575209c96a429411099d143f36cc1a435
編寫生成mysql容器腳本linux
[root@localhost ~]# vim docker_mysql.sh # /usr/bin bash docker run --name mysql \ #建立的容器名稱 -e MYSQL_ROOT_PASSWORD=lujunwen \ #設置mysql密碼 -v /usr/lib/mysql:/usr/lib/mysql \ -p 3306:3306 \ #容器的3306端口映射到宿主機器 -d mysql #後臺運行容器 [root@localhost ~]# sh docker_mysql.sh 63362a2f5744f962c7de19894e87624fa24579a3ca0177113f6703c8b2093250
建立項目的文件夾和nginx配置nginx
[root@localhost ~]# mkdir /docker/code mkdir: 沒法建立目錄"/docker/code": 文件已存在 [root@localhost ~]# mkdir /docker/nginx/conf.d mkdir: 沒法建立目錄"/docker/nginx/conf.d": 文件已存在 [root@localhost ~]# vim /docker/nginx/conf.d/default.conf server { listen 80 default_server; server_name localhost; root /usr/share/nginx/html/; location / { index index.html index.htm index.php; autoindex off; } location ~ \.php(.*)$ { root /var/www/html/; fastcgi_pass 172.17.0.3: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; } }
重啓Nginx容器web
[root@localhost ~]# docker restart nginx nginx
進行檢測redis
建立index文件sql
[root@localhost ~]# echo "< ?php phpinfo(); ?>" > /docker/code/index.php
測試,成功後出現
docker
該php鏡像,不包括pdo_mysql擴展,須要自行安裝,安裝方法以下vim
docker exec -it php bash apt-get -y update apt-get install -y libpng12-dev libjpeg-dev libpq-dev libxml2-dev docker-php-ext-install pdo_mysql pdo_pgsql
若是想要使用redis擴展
pecl install redis-3.1.1 docker-php-ext-enable redis
進入容器bash並進入mysql命令行
[root@localhost docker]# docker exec -it mysql bash root@63362a2f5744:/# mysql -uroot -p lujunwen
docker容器mysql
Myslq設置密碼方法二
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -d mysql