The Docker environment project.
├─ docker-compose.yml
│
├─ mysql
│ └─ my.cnf
├─ nginx
| ├─ conf.d
| ├─ ...
│ └─ Dockerfile
│
├─ php
| ├─ config
| ├─ ...
│ └─ Dockerfile
│
├─ .env
│
1. Install Docker Desktop on Windows:
- Download Docker Desktop for Windows.
https://hub.docker.com/editions/community/docker-ce-desktop-windows/
(*) Requires Microsoft Windows 10 Professional or Enterprise 64-bit, or Windows 10 Home 64-bit with WSL 2.
2. Modify project path
Copy and rename the '.env.example' file to '.env'.
Modify the source directory in .env file.
SOURCE_PATH=<SOURCE DIRECTORY>
VOLUME_PATH=/var/www/html
- Application will be mounted to
/var/www/html
You may modify project paths
Eg:
SOURCE_PATH=C:\workspace\laravel-react-project
- Modify others configurations if needed.
eg: you can modify the port number of http/https instead of the default configuration shown below.
APP_PORT=80
APP_SSL_PORT=443
3. Check configuration of Nginx server
Directory docker\nginx\conf.d\default.conf
server {
...
root /var/www/html/public;
....
location ~ \.php {
fastcgi_pass docker_phpfpm_1:9000;
...
}
}
Explain
- root : the VOLUME_PATH, the project mounted directory
- docker_phpfpm_1 : phpfpm containner, the generated default name
4. Build docker
By using window command line ..etc
1/ Go to docker's directory.
2/ Build image by command.
docker-compose build
3/ Build containner.
docker-compose up
if it's all successed, all the services are running as image below
5. Access local site
- if the default port 80/443 has modified in .env file, it's must be specified in the url properly.
Get inside a containner eg:
docker exec -it docker_nginx_1 bash
docker exec -it docker_phpfpm_1 bash
To update composer packages
composer install
Show docker images (run on host machine)
docker ps
Inspect a container (run on host machine)
eg : check container service redis
docker inspect redis
Check docker network (run on host machine)
docker network ls
Remove specific docker network (run on host machine)
docker network rm NETWORK [NETWORK...]
- (Optional) Cleanup build folder (run on host machine):
docker system prune
- (Optional) Show all images (run on host machine):
docker images
- (Optional) Clean all images and containers (run on host machine):
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
- In .env file, modify the config:
DB_CONNECTION=mysql
DB_HOST=172.20.0.5
DB_PORT=3306
DB_DATABASE=frappe_dev
DB_USERNAME=root
DB_PASSWORD=password
Explain 172.20.0.5 : the configured ip in .env file, specifically it's the value of MYSQL_IPV4_ADDRESS
the docker subnet mark is already in use
So, remove the confict network or changing the config in .env file and build again!
Remove the confict network by following commands
docker network ls
docker network rm NETWORK_NAME
changing the ip config in .env file.
DOCKER_SUBNET=172.20.0.0/16
NGINX_IPV4_ADDRESS=172.20.0.2
PHPFPM_IPV4_ADDRESS=172.20.0.3
REDIS_IPV4_ADDRESS=172.20.0.4
MYSQL_IPV4_ADDRESS=172.20.0.5