Docker and PHP: Difference between revisions
Jump to navigation
Jump to search
Line 48: | Line 48: | ||
<code>-d</code> runs the container as a daemon, and returns the command line immediately. | <code>-d</code> runs the container as a daemon, and returns the command line immediately. | ||
Dockerfile doesn't have to be in a different directory, but this seems to be something of a convention and perhaps keeps things tidy. By default docker-compose will look for a Dockerfile in the current directory. | |||
== Extensions == | == Extensions == |
Revision as of 15:04, 11 June 2021
Contents of a Docker directory
The following files must be present to use docker-compose
:
docker-compose.yml Dockerfile
docker-compose build
will build the image.
Run a basic PHP Docker image
docker run --rm php:7.4-apache-buster php --version
The --rm
argument removes the container after it has finished.
Basic PHP Dockerfile
Build an image and copy in a PHP file:
FROM php:7.4-apache-buster COPY index.php /var/www/html/
To build the image:
docker build -t phpinfo:latest .
To run the image:
docker run --rm -p 8080:80 phpinfo
Basic PHP Docker Compose
version: "3" services: app: image: phpinfo container_name: phpinfo build: context: . dockerfile: docker/Dockerfile ports: - 8080:80
This can be built and run with:
docker-compose up --build -d
-d
runs the container as a daemon, and returns the command line immediately.
Dockerfile doesn't have to be in a different directory, but this seems to be something of a convention and perhaps keeps things tidy. By default docker-compose will look for a Dockerfile in the current directory.
Extensions
PHP extensions can be installed via docker-php-ext-install
, e.g. to install the MySQL extension:
RUN docker-php-ext-install pdo_mysql