18

I'm trying to setup a local development environment in docker that includes nginx and php. I started with this tutorial and have a functioning server. My project requires that a couple PHP extensions be installed, but I'm having difficulty figuring out how to adapt this setup to include them.

The documentation for the image says to put it in a dockerfile, which I have done. However, that gives me an error of:

ERROR: The Compose file is invalid because: Service php has both an image and alternate Dockerfile. A service can either be built to image or use an existing image, not both.

My docker-compose.yml:

web:
  image: nginx:latest
  ports:
    - "80:80"
  volumes:
  - ./code:/code
  - ./site.conf:/etc/nginx/conf.d/site.conf
  links:
    - php
php:
  dockerfile: extensions
  image: php:7-fpm
  volumes:
    - ./code:/code

My extensions file

RUN docker-php-ext-install zip
RUN docker-php-ext-install gd
RUN docker-php-ext-enable zip
RUN docker-php-ext-enable gd

Clearly I'm going about this wrong. Is there a way to install the extensions into this image, or do I need to create my own? I'm using Docker for Windows.

1
  • 1
    you have to build the image yourself, if you use image: in compose file it never read the Dockerfile Commented Apr 16, 2018 at 21:45

2 Answers 2

13

this is my code. its already running on my server.

web:
  image: nginx:latest
  ports:
    - "80:80"
  volumes:
  - ./code:/code
  - ./site.conf:/etc/nginx/conf.d/site.conf
  links:
    - php
php:
  #remove this
  #dockerfile: extensions
  #image: php:7-fpm
  #change with build ...
  build: './docker/php'
  volumes:
    - ./code:/code

Then, add Dockerfile file to the docker/php folder:

FROM php:7-fpm

RUN apt-get update && apt-get install -y \
        libicu-dev \
    && docker-php-ext-install \
        intl \
    && docker-php-ext-enable \
        intl

Now you can run Dockerfile inside docker-compose.

Sign up to request clarification or add additional context in comments.

Comments

8

In your extensions file, add this to the top: FROM php:7-fpm

and remove the image: php:7-fpm from your docker-compose file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.