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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With