Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - how to set up Apache + PHP in docker-compose.yml

I use this to set up nginx for PHP:

nginx:
    image: nginx:latest
    ports:
        - 8080:80
    volumes:
        - ./code:/code
        - ./site.conf:/etc/nginx/conf.d/site.conf
    links:
        - php
php:
    image: php:7-fpm
    volumes:
        - ./code:/code

But how about Apache? How can I set up Apache + PHP in docker-compose.yml?

Following this guide:

version: '2'

services:
  php:
    build: php
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./php/www:/var/www/html

Error:

ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.

Any ideas? I'm on Xubuntu 16.04.

EDIT:

After managing to upgrade docker-compose to 1.9, I try with this file below:

version: '2'
services:
    php:
        build: php
        expose:
            - 9000
        volumes:
            - ./php/www:/var/www/html

    apache2:
        image: webdevops/apache:latest
        args:
            - PHP_SOCKET=php:9000
        volumes:
            - ./php/www:/var/www/html
        ports:
            - 80:80
            - 443:443
        links:
            - php

Error:

$ sudo docker-compose up -d
Building php
ERROR: Cannot locate specified Dockerfile: Dockerfile

Docker is such as pain!

Any ideas how to fix this?

like image 748
Run Avatar asked Jan 02 '17 08:01

Run


People also ask

Can I run Apache in docker?

To run the Apache container, you will need to run the Docker command as follows: 1. Invoke the docker run command to create a new container based on your downloaded Apache Docker image. The docker run command then returns the unique container ID of the container you've just created.

Can I run PHP in docker?

You can use docker run to create a container and execute PHP. You just need to add some volumes to the container. These volumes should include the paths to your code.


2 Answers

I would choose webdevops dockerized apache, because it has simple configuration:

version: '2'
services:
    php:
        build: php
        expose:
            - 9000
        volumes:
            - ./php/www:/var/www/html

    apache2:
        image: webdevops/apache:latest
        args:
            - PHP_SOCKET=php:9000
        volumes:
            - ./php/www:/var/www/html
        ports:
            - 80:80
            - 443:443
        links:
            - php
like image 51
rokas Avatar answered Oct 11 '22 05:10

rokas


Since the example above does not work, here is a different approach: docker-compose.yml

version: '3.1'

services:
  php:
    image: php:7.4-apache
    ports:
      - 80:80
    volumes:
      - ./php/www:/var/www/html/

Launch the server with

docker-compose up
like image 26
meles Avatar answered Oct 11 '22 06:10

meles