- Install Docker Desktop for Windows (x64). https://docs.docker.com/desktop/install/windows-install/
- Open
Command Prompt
asAdministrator
and typewsl --update
. - Install VS Code, use default options, add context to path. https://code.visualstudio.com/
- Open VS code & update as needed.
- Unzip https://github.com/NetSamurai/phpMongoDB/archive/refs/heads/main.zip to a folder you want to be the workspace and rename the folder within to
phpMongoDB
. - Open the extracted folder, and right click
phpWithMongoDB
folder and selectRun with (VS) Code
. - On left pane, click
docker-compose.yaml
. - For first time installs of Visual Studio Code Only, it may ask you in the bottom right corner of Visual Studio code to get
Docker
andWSL
extension for VS Code- click yes. If this is needed, close VS Code after it's done installing, and repeat Step 6 and 7 after. - In VS Code, on the top menu bar, open a
Terminal > New Terminal
. - In VS Code terminal, Clear docker cache by running:
docker system prune -f
docker image prune -a -f
docker volume prune -f
- Note: This step is only neccessary because this example I built is of an interactive docker build and not a stored image.
- Inside the VS Code Terminal, issue the start command
docker compose up -d
. - If any firewall stuff pops up right now click Allow / Yes. You now have a server.
- http://localhost:8000/ is your website.
- http://localhost:8081/ is your database frontend - admin/pass is the
HTTP basic auth
. admin/password is theMongoDB
login. - In the extracted folder you'll see it added files to the workspace, dont delete those, its the database.
- Change all desired PHP code in the
/app
folder.
Notes:
function | how-to |
---|---|
Stop your server | Open your project folder in VSCode, then in the terminal type: docker compose down . |
Start your server | Open your project folder in VSCode, then in the terminal type: docker compose up -d . (Omit -d to see all logs in terminal, ctrl-c stops) |
What containers are we running here? | See all services defined in docker-compose.yaml |
How is the PHP image built? | See Dockerfile |
Open your project folder in VSCode, then in the terminal type:
docker exec -it mongodb bash
mongosh mongodb://admin:password@mongodb:27017
First command goes inside your docker container of MongoDB
, the second one, from within that container, goes inside mongo itself. Once in a container exit
will bring you back to the previous scope.
This is not a production ready docker build for this stack, it's merely a scaffolding for development and testing.