I trying to use Docker for my Symfony3 project I got it running but I get this error:
The LDAP PHP extension is not enabled.
It does sound right as I am using Ldap extension for my project. I have tried installing the Ldap extension using Dockerfile for my php image which seems to install it but still gives me this error.
Q1) How do I install required php extensions to my php image.
Q2) Once extension installed how do i enable it.
docker-compose.yml:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
project files
volumes_from:
- php
links:
- php
php:
image: php:5.6-fpm
volumes:
- ./project_code:/var/www/project
Dockerfile:
FROM php:5.6-fpm
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install php5-ldap -y
You need to point in your docker-compose.yml to the directory containing your Dockerfile. Then it builds your individual image based on this Dockerfile and links it as desired in docker-compose.
So you have to modify your docker-compose.yml. Lets assume you have stored your Dockerfile in the same directory as your docker-compose.yml file. Then you have to change it as follows:
version: '2' # <--
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
project files
volumes_from:
- php
links:
- php
php:
build: . # <--
volumes:
- ./project_code:/var/www/project
This builds your image as defined in the Dockerfile (currently your Dockerfile is ignored by your docker-compose.yml file). You then have to add to the Dockerfile how to enable your php module.
if you didn't find php.ini with php -i | grep php.ini
In docker, there are two php.ini files: php.ini-development and php.ini-production
https://docs.docker.com/samples/library/php/
Related
I'm new to Docker and want to build the image myself (nginx + php-fpm + mariadb + phpadmin).
I want to have Xdebug so I've a Dockerfile to customize the php-fpm image.
And then I run into a problem (same as here) when I execute
docker-compose --build
or
docker-compose up --build
The image was built ok first time, but for next times it fails because the php-fpm somehow ended up with already installed xdebug:
+ pecl install xdebug
pecl/xdebug is already installed and is the same as the released version 3.1.5
install failed
It is like the image comes from cache but Dockerfile is still applied.
I've used the solution from that post but I am clearly missing something, it should not be like that. What am I doing wrong?
My docker-compose:
version: "3.7"
services:
web:
image: nginx:1.17
ports:
- 8080:80
volumes:
- ../logs:/var/log/nginx/
- ../wordpress:/var/www/myapp
- type: bind
source: ./site.conf
target: /etc/nginx/conf.d/default.conf
depends_on:
- php
- mariadb
php:
image: php:7.4-fpm
build:
context: ./php
volumes:
- ../wordpress:/var/www/myapp
- type: bind
source: ./php/conf.d/xdebug.ini
target: /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- type: bind
source: ./php/conf.d/error_reporting.ini
target: /usr/local/etc/php/conf.d/error_reporting.ini
depends_on:
- mariadb
mariadb:
image: mariadb:10.4
restart: always
ports:
- 127.0.0.1:3308:3306
environment:
- MYSQL_ROOT_PASSWORD=4321
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=1234
volumes:
- mariadb-data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- 8900:80
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mariadb
depends_on:
- mariadb
volumes:
mariadb-data:
and my php-fpm dockerfile:
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y \
libicu-dev\
openssl \
git \
unzip\
nano\
&& docker-php-ext-install \
intl pdo pdo_mysql mysqli\
&& docker-php-ext-enable \
intl pdo pdo_mysql
RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\
|| (pecl install xdebug && docker-php-ext-enable xdebug)'
Discussion/Explanation
What am i doing wrong?
Perhaps it is a misunderstanding of the docker-compose.yml template, specifically in regards of the container for the php service (based on php:7.4-fpm) which might have been introduced in error.
When you specify both the image and the build attribute of a service, the image as you build it will be stored under the image name (see also later References section).
As you name the image as php:7.4-fpm and those build images are stored locally (there where you run docker-compose(1)) and you have in your Dockerfile within that build context that image same name php:7.4-fpm:
FROM php:7.4-fpm
# ...
Then when you build for the first time, the image php:7.4-fpm is not available locally. Then it is build from Docker Hub fetched php:7.4-fpm and the build result is then overwriting the image php:7.4-fpm locally as you are using the same name (!).
This is most likely not intended.
This can also explain why --build --force-recreate does not work either: The Dockerfile build instructions consider php:7.4-fpm to be the image to be built from but it is already the result (of the first local build).
Solution
Remove the image service keyword. You don't need it as you have the build keyword. Docker Compose will take care and name the image within your project automatically (based on service- and project name).
services:
php:
build:
context: ./php
volumes:
- ../.:/var/www/myapp:ro
Then remove the dangling/tainted php:7.4-fpm image:
$ docker image rm php:7.4-fpm
These two steps should already solve your issue and get your docker composition up without errors.
Additionally you can remove the workaround and do a plain pecl install xdebug && docker-php-ext-enable xdebug, here with better debugging abilities for the build (set -ex):
FROM php:7.4-fpm
RUN set -ex ;\
apt-get update ;\
apt-get install -y \
libicu-dev\
openssl \
git \
unzip \
nano \
;\
docker-php-ext-install intl pdo pdo_mysql mysqli ;\
docker-php-ext-enable intl pdo pdo_mysql ;\
:
RUN set -ex ;\
pecl install xdebug ;\
docker-php-ext-enable xdebug ;\
:
You could further tweak this by making the FROM image a build argument, bind it in the docker-composer.yml template (and use variables and defaults there-in, too). I'll leave that to your liking.
References
If you specify image as well as build, then Compose names the built image with the webapp and optional tag specified in image:
build: ./dir
image: webapp:tag
This results in an image named webapp and tagged tag, built from ./dir.
From: https://docs.docker.com/compose/compose-file/compose-file-v3/#build
When starting the containers, you will need to instruct docker-compose to rebuilt the dockerfile.
Try this:
docker-compose up --build --force-recreate
I'm trying to set up my symfony project in docker, and i'M struggling building the php container.
I've put all my source code in \var\www\app\
Here is an extract of my docker-compose.yml:
php:
build:
context: .
dockerfile: docker/php/Dockerfile
volumes:
- '/var/www/app:/var/www'
restart: on-failure
env_file:
- .env
user: 1000:1000
nginx:
image: nginx:1.19.0-alpine
restart: on-failure
volumes:
- '/var/www/app:/var/www'
- './docker/nginx/app.conf:/etc/nginx/conf.d/app.conf:ro'
ports:
- '80:80'
depends_on:
- php
here's the Dockerfile:
FROM composer:2.0 as composer
FROM php:7.4-fpm
RUN docker-php-ext-install pdo_mysql
RUN pecl install apcu
RUN apt-get update && \
apt-get install -y \
libzip-dev
RUN docker-php-ext-install zip
RUN docker-php-ext-enable apcu
WORKDIR /var/www
COPY --chown=1000:1000 var/www/app /var/www
RUN PATH=$PATH:/usr/src/app/vendor/bin:bin
RUN composer install --no-scripts --prefer-dist \
&& rm -rf "$(composer config cache-dir)" "$(composer config data-dir)"
and here's the error I get while trying to build the php container:
Step 9/11 : COPY --chown=1000:1000 var/www/app /var/www
ERROR: Service 'php' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder883740312/var/www/app: no such file or directory
The problem, I guess, is that it tries to fetch file within the docker build folder instead of /var/www/app. I thought it was because of the context, and I've tried to change it but then it cannot find my Dockerfile anymore.
I don't see how to resolve this, yyet I have the feeling it is a veryy easy one...But I'm quite lost at the moment.
Thanks!
You try to COPY a folder at build time and then at runtime you replace the same by using a VOLUME in your docker-compose. Maybe the volume is not needed?
Regarding the error, docker expects your var folder to be at the same level as docker-compose.yml. If that is not the case and your var folder is in docker/php/, then that is what you have to set as context in your docker-compose.yml.
php:
build:
context: docker/php
dockerfile: Dockerfile
If the Dockerfile is in the context, you don't even need to declare it explicitly in the docker-compose.yml
I currently have a problem running my apache web-server successfully while using Docker...
Here is my docker file:
FROM fedora:27
# Container Owner
MAINTAINER nzhiti#gmail.com
# Update & install Apache & clean dnf
RUN dnf upgrade -y
RUN dnf install -y httpd
RUN dnf clean packages
RUN dnf install -y mod_ssl
# Configuring hosts
ADD ./hosts/hosts /etc/hosts
# Port
EXPOSE 443
# Starting httpd
ENTRYPOINT ["/usr/sbin/httpd"] & CMD ["-D", "FOREGROUND"]
No errors during building. But when I try to compose it, it never works, and the only message outputted is apache exiting with code 0
version: '3'
services:
php-apache:
image : httpd_fedora
ports:
- 443:443
volumes:
- ./Apache/www/:/var/www/html
- ./Apache/vhosts/:/etc/httpd/conf.d/
- ./Apache/SSLcert/:/etc/httpd/ssl/
- ./Apache/errorlogs/error.log:/var/log/httpd/error.log
tty: true
I'm out of ideas...
Thanks,
DRK
Try indenting tty: true so it's aligned with php_apache properties. Also copy the Dockerfile to the same directory of docker-compose.yml, and change image to build: ..
version: '3'
services:
php-apache:
build: .
ports:
- 443:443
volumes:
- ./Apache/www/:/var/www/html
- ./Apache/vhosts/:/etc/httpd/conf.d/
- ./Apache/SSLcert/:/etc/httpd/ssl/
- ./Apache/errorlogs/error.log:/var/log/httpd/error.log
tty: true
Having this lamp docker setup (Im a sort of docker newbie):
docker-compose.yml
version: '2'
services:
webserver:
build: .
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www/html
links:
- db
db:
image: mysql:5.6
ports:
- "3306:3306"
volumes:
- /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=adminpasswd
- MYSQL_DATABASE=se_racken_dev
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- "88:80"
links:
- db:db
Dockerfile
FROM php:5.6-apache
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
Just cant get my local environment to work.
Get this error message at localhost:8088:
SQLSTATE[HY000] [2002] No such file or directory
How can I configure my docker setup to get past this connection problem?
Got some hints here:
Starting with Zend Tutorial - Zend_DB_Adapter throws Exception: "SQLSTATE[HY000] [2002] No such file or directory"
Do I need to install vim and do what they suggest in above or can I solve it in my docker files?
On webserver image you should define the connection values such as database's hostname,database name, username and password.
What can you can is to specify a .env file as seen in https://docs.docker.com/compose/env-file/
In your case that should be:
DB_HOSTNAME=db:/var/run/mysqld/mysqld.sock
DB_USER=root
DB_PASSWORD=somepassword
DB_NAME=se_racken_dev
Then to your Dockerfile specify:
FROM php:5.6-apache
ENV MYSQL_HOSTNAME="localhost"
ENV MYSQL_PASSWORD=""
ENV MYSQL_USERNAME="root"
ENV MYSQL_DATABASE_NAME=""
RUN apt-get update -y && apt-get install -y libpng-dev curl libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
Then modify your docker-compose.yml like that:
version: '2'
services:
webserver:
build: .
ports:
- "8080:80"
- "443:443"
volumes:
- ./:/var/www/html
links:
- db
environment:
- MYSQL_HOSTNAME=$DB_HOSTNAME
- MYSQL_PASSWORD=$DB_USER
- MYSQL_USERNAME=$DB_PASSWORD
- MYSQL_DATABASE_NAME=$DB_NAME
db:
image: mysql:5.6
ports:
- "3306:3306"
volumes:
- /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD
- MYSQL_DATABASE=$DB_NAME
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- "88:80"
links:
- db:db
Then you can use php's getenv to retreive the values from enviromental variables you specified. eg In your case the getenv('MYSQL_DATABASE_NAME') will retreive the value "se_racken_dev" as a string. So you need to modify the database configuration file in order to retreive correctly the database connection credentials using the function mewntioned above.
A simple way to remember is whatever you specify via ENV in your dockerfile you can retreive via getenv.
I have two docker compose files that I start with docker-compose f- docker-compose.yml -f docker-compose-osx.yml up
The file contents is:
docker-compose.yml:
version: '2'
services:
fpm:
image: sbusso/php-fpm-ion
nginx:
image: nginx:stable
ports:
- "80:80"
links:
- fpm
- db
db:
image: orchardup/mysql
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: myproject
and
docker-compose-osx.yml
version: '2'
services:
fpm:
links:
- sync
volumes_from:
- sync
db:
links:
- sync
volumes_from:
- sync
nginx:
links:
- sync
volumes_from:
- sync
sync:
image: zeroboh/lsyncd
volumes:
- /var/www/html
- ./src:/src:Z
- ./docker-config/nginx:/etc/nginx/conf.d
- /var/lib/php/session
- ./docker-config/lrsync/lrsync.lua:/etc/lrsync/lrsync.lua
- ./sync:/sync
Usually when I connect to my fpm container I need to run grunt, but grunt and npm are not known to my docker container.
How can I integrate grunt here in my docker-compose files?
Thanks!
You fpm container (sbusso/php-fpm-ion) doesn't have grunt and npm installed (neither its base image). You can see that by reading the Dockerfile here.
sbusso/php-fpm-ion is based on sbusso/php-fpm which is based on debian:jessie. You can install npm and grunt as if you were on any Debian system. The npm version available in debian packages is quite old, you should see their installation guide on the website and then install grunt with npm install -g grunt-cli
Keep in mind that containers are isolated from the host, they cannot share neither file nor binaries. Even if you have npm and grunt installed on your host, your container cannot launch them.