PHP 8.5 in Docker

Contents
The php:8-cli image
Run one-liners
Mount your code
Serve a page

The php:8-cli image

The official image php:8-cli bundles the PHP 8.5 command line with nothing else to configure. The tag has two parts: 8 pins the major version and cli picks the variant without a web server.

Pulling the image once is enough - Docker reuses it for every run below, so each example starts fast.

Run one-liners

Containers are throwaway by design: the --rm flag removes the container when the command ends while the image stays cached. Run the version check through the image with one line:

Check the PHP version inside Docker

docker run --rm php:8-cli php -v

PHP 8.5.0 (cli) (built: Nov 2026) (NTS) Copyright (c) The PHP Group

The output is the same version report you get from a local install. Any php command works this way: put it after the image name and Docker runs it inside the container.

Mount your code

Your files live on the host, so mount the project folder into the container. The -v flag maps the current folder to /app inside the container and -w makes it the working folder. With the mount in place the container sees hello.php exactly as saved on disk:

Run a local file inside the container

docker run --rm -v "$PWD":/app -w /app php:8-cli php hello.php

Hello from Docker.

Serve a page

The built-in server works from a container too. Publish port 8000 so the browser on the host can reach it, keep the folder mount from the previous step, and start the server bound to all interfaces. Open port 8000 in a browser to see the project, and stop the container with Ctrl+C when done.

Serve the project from Docker

docker run --rm -p 8000:8000 -v "$PWD":/app -w /app php:8-cli php -S 0.0.0.0:8000

Document root is /app

Next: PHP course

Article author: Arthur Isaev

Related articles
Development with PHP
PHP course: zero to hero in 50 lessons
What is PHP and where it runs
Install PHP 8.5 and run your first command
Your first PHP script
Comments in PHP
Variables and constants
Types in PHP
Strings in PHP
Numbers in PHP
Operators
if and else
switch and match
Ternary, null coalescing and nullsafe
Loops
Arrays
Associative arrays
Functions
Variable scope
include and require
Namespaces
Composer and autoloading
Everyday string functions
Dates and time
JSON in PHP
Reading and writing files
Errors: read, reproduce, fix
Classes and objects
Constructors and promotion
Inheritance
Interfaces and traits
Enums
Magic methods
Attributes
Exceptions
Strict types
Closures and arrow functions
Generators with yield
Forms: GET and POST
HTTP: headers and status codes
Cookies
Sessions
Login with sessions
JSON REST endpoint
Database with PDO
Uploads and .htaccess
Lint like a pro
Clean functions
Debugging
Modern PHP tour: 5 to 8.4
PHP 8.5 for busy developers
Hero roadmap: the whole course on one page
Install PHP 8.5 on Windows 11
Install PHP 8.5 on Ubuntu
Install PHP 8.5 on Rocky Linux
Install PHP 8.5 on macOS
Install PHP 8.5 on FreeBSD
PHP 8.5 in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: