Original: 61204205
You first confirm the two things: 1) perform Docker exec-it dream.php bash, to the PHP storage directory to see if you do not see your files, directory mapping is mostly problematic ; 2) confirm the path of the Fastcgi_param setting, First match the absolute path (as above) to try it.
--------------------------------------------------------------------------------------------------------------- -----------------------
0 Mission Brief
- Installing in aUbuntu 16.04virtual machinedocker
- Using thedockerInstallationPostgreSQL
- Complete port mapping allows the external machine to access the database in the virtual machine
1 Installing Docker
This part is relatively simple, but considering the completeness, let's make a list.
I chose this timedocker-ce, the installation process is as follows:
1.1 Establishment of repository
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
1.2 Installing Docker
sudo apt-get update
sudo apt-get install docker-ce
2 Installing PostgreSQL
docker pull postgres:9.4
3 Creating a container
Docker containers are only accessible by the local host by default, that is, the container on host a cannot be accessed by Host B, so port mapping is done.
--name postgres1 -e POSTGRES_PASSWORD=password -p 54321:5432 -d postgres:9.4
Explain:
run, create and run a container;
--name, specifying the name of the container to be created;
-e POSTGRES_PASSWORD=password, set environment variables, specify the login password for the databasepassword;
-p 54321:5432, the port mapping maps the container's 5432 port to the 54321 port of the external machine;
-d postgres:9.4, specify usepostgres:9.4as mirror.
3.1 Validation Results
Afterdocker ps -athat, the results are similar to the following table:
CONTAINER ID |
IMAGE |
COMMAND |
CREATED |
STATUS |
PORTS |
NAMES |
F6951e0c5c77 |
postgres:9.4 |
"Docker-entrypoint ..." |
Minutes ago |
Up minutes |
0.0.0.0:54321->5432/tcp |
Postgres1 |
3.2 Key points
I encountered a lot of holes in my own installation, and I think the most important point is the order of the parameters in the Docker command.
For example, if the location of the port map is-p 54321:5432too close, it will cause the mapping to fail.
4 Connecting the database
Previous preparations have been completed, and the next step is to access the database from outside.
This step is quite routine:
-U postgres -h 192.168.100.172 -p 54321
Attention:
Postgres The default user name for the imagepostgres,
The login password for the Create container is the specified value.
5 References
[1] Docker website
[2] postgres image Official document
[3] Very detailed Docker learning notes
------------------------------------------------------------------------------------------Docker Nginx PHP-FPM The Configuration----------------------------
Original: 1190000007056245
After reading the official Docker tutorial, want to set up a local PHP development environment, can search a lap, also did not find a particularly satisfactory article, a good summary.
Assume
- You know what Nginx and php-fpm are.
- You know the basic Docker commands.
Operating Environment
MacBook Pro,osx 10.11.5
Start PHP-FPM
Explain that PHP needs to be php-fpm and let it run first:
-d -v ~/Workspace/tmp/www:/var/www/html:ro php:7.1-fpm
Description
- dream-php is the name of the container.
- ~/workspace/tmp/www is the local PHP file storage directory,/var/www/html is the container inside the PHP file storage directory, RO is read-only.
Edit Nginx configuration file
Local Storage path:
~/Workspace/tmp/docker/nginx/conf.d/default.conf
Configuration file Contents:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
Description
- php:9000 represents the URL of the PHP-FPM service, which is also mentioned below.
- /var/www/html is the storage path for PHP files in dream-php , which is mapped by Docker and becomes the local path ~/workspace/tmp/www (you can take a look at the PHP-FPM start command)
Start Nginx
docker run --name dream-nginx -p 80:80 -d -v ~/Workspace/tmp/www:/usr/share/nginx/html:ro -v ~/Workspace/tmp/docker/nginx/conf.d:/etc/nginx/conf.d:ro --link dream-php:php nginx
Description
- -P 80:80 is used to add port mappings, exposing 80 ports in the Dream-nginx .
- ~/WORKSPACE/TMP/WWW is the storage directory for the local HTML file, and/usr/share/nginx/html is the storage directory for the HTML file inside the container.
- ~/WORKSPACE/TMP/DOCKER/NGINX/CONF.D is the storage directory for the local nginx configuration file, and the/ETC/NGINX/CONF.D is the storage directory for the Nginx configuration file in the container.
- --link dream-php:php the dream-php network into Dream-nginx, and by modifying Dream-nginx , the domain name PHP maps to 127.0.0.1, allowing Nginx to access php-fpm through php:9000.
Test results
In ~/workspace/tmp/www, two files are delegated:
Index.html
<html><body><h1>Hello World</h1></body></html>
phpinfo.php
<?php phpinfo();
Next look at the results:
- http://localhost
- http://localhost/phpinfo.php
If you see Hello world and a familiar phpinfo, you're done.
When accessing index.html, Nginx reads/usr/share/nginx/html/index.html, which is transformed into a local ~/workspace/tmp/www/by Dream.nginx conversion. Index.html.
When accessing phpinfo.php, Nginx let php-frm execute/var/www/html/phpinfo.php, this path is converted to ~/workspace/tmp/www/by dream.php phpinfo.php.
FAQs
How to observe the file system in the container:
docker exec -it dream-nginx bash
"Go" Docker installation PostgreSQL