Docker and PHP: Difference between revisions

From Rixort Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 27: Line 27:


  docker run --rm -p 8080:80 phpinfo
  docker run --rm -p 8080:80 phpinfo
== Basic PHP Docker Compose ==
version: "3"
services:
  app:
    image: laravel-www
    container_name: laravel-www
    build:
      context: .
      dockerfile: docker/Dockerfile
    ports:
      - 8080:80

Revision as of 20:24, 20 March 2020

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 php:7.3-apache-stretch php --version

Basic PHP Dockerfile

Build an image and copy in a PHP file:

FROM php:7.2-apache-stretch

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: laravel-www
    container_name: laravel-www
    build:
      context: .
      dockerfile: docker/Dockerfile
    ports:
      - 8080:80