Helle everyone.
I've a little issue with Docker.
I try to create a basic docker-composer.yml for my projects with Laravel.
So here is my docker-compose.yml which is in the root directory of my project :
version: '2'
services:
php:
container_name: php
build:
context: ./
dockerfile: docker/app.docker
volumes:
- ./:/var/www
links:
- mysql
- redis
- cache
environment:
- "DB_PORT=3306"
- "DB_HOST=mysql"
- "REDIS_PORT=6379"
- "REDIS_HOST=redis"
nginx:
container_name: nginx
build:
context: ./
dockerfile: docker/web.docker
volumes:
- ./:/var/www
ports:
- "80:80"
- "443:443"
- "9000:9000"
links:
- php
mysql:
container_name: mysql
image: mysql:5.7.18
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=docker"
ports:
- "3306:3306"
redis:
container_name: redis
image: redis:3.0
ports:
- "6379:6379"
cache:
container_name: memcached
image: memcached:alpine
ports:
- "11211:11211"
So as you can see, I try to install several containers : PHP, Nginx, MySql, Redis and Memcached.
Now here is my docker file for my PHP container :
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
It's the code I've found on the docker website.
But the docker-compose up command start well and crash while executing the configuration file.
It returns
Step 1/2 : FROM php:7.0-fpm
---> e04605d12f83
Step 2/2 : RUN apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev && docker-php-ext-install -j$(nproc) iconv mcrypt && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd
---> Running in fd19753fb969
ERROR: Service 'php' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng-dev && docker-php-ext-install -j$(nproc) iconv mcrypt && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install -j$(nproc) gd'
returned a non-zero code: 139
Does anybody already has this kind of error ? I've tried with PHP 7.1 fpm, same error is triggered.
I don't see what is wrong.
Do not hesitate to ask me some other parts of code.
Thanks for your help.
I tried your PHP configuration and it did not give me any problem when compiling the image
As an alternative:
Try:
FROM php:7-fpm-alpine
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-gd \
--with-freetype-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-install -j${NPROC} gd && \
apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
Related
I'm running docker-compose up to build my project and when it goes through the update of container dependencies it throws me the following error.
Dockerfile:
FROM php:7.2.17-apache-stretch
RUN mkdir /var/www/html/public /etc/apache2/ssl
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash
RUN apt-get update && \
apt-get install -y \
zip unzip git nodejs libmcrypt-dev libxml2-dev libpng-dev libzmq3-dev libzip-dev libkrb5-dev libc-client-dev \
libnotify-bin zlib1g-dev libicu-dev libmagickwand-dev libmagickcore-dev && \
rm -r /var/lib/apt/lists/* && \
pecl install dbase-7.0.0beta1 imagick
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
docker-php-ext-configure zip --with-libzip && \
docker-php-ext-install pdo pdo_mysql soap gd imap && \
docker-php-ext-install zip && \
docker-php-ext-enable dbase imagick
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
COPY certificates/ /etc/apache2/ssl/
RUN sed -i "s|DocumentRoot /var/www/html|DocumentRoot /var/www/html/public|g" /etc/apache2/sites-available/000-default.conf && \
echo "upload_max_filesize = 20M" >> /usr/local/etc/php/conf.d/docker-php-conf.ini && \
touch /etc/apache2/sites-enabled/000-default-ssl.conf && \
echo "<VirtualHost *:443>\n \
DocumentRoot \"/var/www/html/public\"\n \
ServerName localhost\n \
SSLEngine on\n \
SSLCertificateFile \"/etc/apache2/ssl/server.pem\"\n \
SSLCertificateKeyFile \"/etc/apache2/ssl/server.key\"\n \
</VirtualHost>" >> /etc/apache2/sites-enabled/000-default-ssl.conf
RUN a2enmod rewrite headers && \
a2enmod ssl
RUN service apache2 restart
docker-compose.yaml:
version: '3.5'
services:
debito:
build:
context: '.'
container_name: debito
volumes:
- .:/var/www/html
ports:
- 32770:80
- 32990:443
networks:
backend:
aliases:
- decreditos
redis:
container_name: debito-redis
image: redis:5
ports:
- 6383:6379
networks:
backend:
aliases:
- decreditos
networks:
backend:
name: decreditos
If someone can help me I would really appreciate it since I've been wanting to find this for a long time and I can't find the solution
Please help with code for dockerfile and docker-compose file i need laravel setup and postgres.
This is my docker file
FROM php:7.4
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
zlib1g-dev \
libpq-dev \
libxml2-dev \
libzip-dev \
libonig-dev \
graphviz \
&& docker-php-ext-configure gd \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install pdo_psql \
&& docker-php-ext-install zip \
&& docker-php-ext-install sockets \
&& docker-php-source delete \
&& curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY . .
RUN composer install
CMD php artisan serve --host=0.0.0.0
EXPOSE 8000
this is docker-compose.yml file
version: '3'
services:
php_4:
build:
context: .
dockerfile: Dockerfile
volumes:
- ./:/var/www/html
ports:
- "8000:8000"
depends_on:
- postgres_4
postgres_4:
image: postgres
restart: unless-stopped
ports:
- "5433:5432"
volumes:
- ./docker/postgres:/var/lib/postgresql/data
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: lara_4
POSTGRES_HOST_AUTH_METHOD: "trust"
Both are not working giving different different errors. SO please anyone give fresh code for both dockerfile and docker-compose file for laravel with postgresql using docker.
You should specify web server, i.e. nginx in docker-compose.yml file
You should take a look at Laravel Sail if you're just starting out with Laravel + Docker.
For your question in general, please edit your question and insert the specific errors.
I have a PHP-based Docker container with Composer and Symfony installed inside of it. But each time I start that container, a message from Symfony appears, proposing to download & install the last version (and to activate TLS), which I do (for both). So I think the upgrade doesn't persist, how can I solve this ? (thank you in advance)
Thank you for your answers, everyone. The docker-composer.yaml and php/Dockerfile are made from a French tutorial video, slightly modified due to improvements noted in the Youtube comment section: The video is called "Un environnement de développement Symfony 5 avec Docker et Docker-compose" from Yoandev Co. Here is the docker-compose.yaml :
version: "3.8"
services:
db:
image: mariadb
container_name: db_SF_tuto_2
restart: always
volumes:
- db-data2:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: admin
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
networks:
- dev2
phpmyadmin:
image: phpmyadmin
container_name: phpmyadmin_SF_tuto_2
restart: always
depends_on:
- db
ports:
- 8090:80
environment:
PMA_HOST: db
networks:
- dev2
maildev:
image: maildev/maildev
container_name: maildev_SF_tuto_2
command: bin/maildev --web 80 --smtp 25 --hide-extensions STARTTLS
ports:
- "8091:80"
restart: always
networks:
- dev2
www:
build: php
container_name: www_SF_tuto_2
ports:
- "8742:8000"
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- ./:/var/www
restart: always
networks:
- dev2
networks:
dev2:
volumes:
db-data2:
… and php/Dockerfile :
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends \
locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev unzip \
\
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
\
&& curl -sS https://getcomposer.org/installer | php -- \
&& mv composer.phar /usr/local/bin/composer \
\
&& curl -sS https://get.symfony.com/cli/installer | bash \
&& mv /root/.symfony/bin/symfony /usr/local/bin \
\
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo_mysql gd opcache intl zip calendar xsl \
\
&& pecl install apcu && docker-php-ext-enable apcu
WORKDIR /var/www/
As you have discovered, container storage is temporary and any changes done in it will be discarded when the container is removed. Note that you can stop a running container and the changes will still be there the next time you launch it, but docker-compose down does remove it, so every time you boot up your symfony binary is being reloaded from the image.
If you want for the updates to persist you'll have to create a volume.
However, since your current installation directory already contains binaries from your base image I'd suggest installing to a different directory and mount that.
In your Dockerfile, change the installation target. Since its a new directory you need to add it to the current $PATH so the tools can be executed.
FROM php:7.4-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf \
\
&& apt-get update \
&& apt-get install -y --no-install-recommends \
locales apt-utils git libicu-dev g++ libpng-dev libxml2-dev libzip-dev libonig-dev libxslt-dev unzip \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& echo "fr_FR.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen \
\
&& mkdir /opt/bin -p \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir /opt/bin --filename composer \
&& curl -sS https://get.symfony.com/cli/installer | bash -s - --install-dir /opt/bin \
\
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo_mysql gd opcache intl zip calendar xsl \
\
&& pecl install apcu && docker-php-ext-enable apcu
ENV PATH /opt/bin:$PATH
WORKDIR /var/www/
Now specify where to map the volume in the docker-compose.yml file:
www:
# ...
volumes:
# Specify the mount point.
# If you use short syntax here, a volume will be created every restart.
- phptools:/opt/bin
volumes:
# Declare a named volume so it can be remounted
phptools:
Run docker-compose build and docker-compose up.
I am using Nging+php-fpm in Docker on Mac OS.
I am trying to debug my app, but PHPStorm does not stop on breakpoints.
Here is my docker-compose.yml
version: '3'
services:
app_php:
build:
context: ./docker/php
dockerfile: Dockerfile
args:
USER_ID: 1000
GROUP_ID: 1000
restart: always
environment:
XDEBUG_CONFIG: remote_host=192.168.0.92
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./web:/var/www/html
depends_on:
- db
- redis
web_nginx:
image: nginx:1.17.9-alpine
restart: always
ports:
- 8090:80
volumes:
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
- ./web:/var/www/html
depends_on:
- app_php
Here is Dockerfile
FROM php:7.4-fpm-alpine3.11
# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN apk add --no-cache \
shadow \
freetype \
freetype-dev \
ghostscript \
ghostscript-fonts \
gmp-dev \
graphicsmagick \
libjpeg-turbo \
libjpeg-turbo-dev \
libpng \
libpng-dev \
libwmf \
libxml2-dev \
libzip \
libzip-dev \
icu \
icu-dev \
git \
vim
# most likely used for local dev only
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN usermod -u ${USER_ID} www-data \
&& groupmod -g ${GROUP_ID} www-data
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure zip
RUN pecl install redis \
&& docker-php-ext-enable redis
RUN docker-php-ext-install -j$(nproc) gd mysqli soap zip intl
ENV PHP_CONFIG_DIR /usr/local/etc/php
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del -f .build-deps \
&& echo "zend_extension=$(find $(php-config --extension-dir) -name xdebug.so)" > $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_enable=1' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_port=10000' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_connect_back=1' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.remote_autostart=0' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.idekey="PHPSTORM"' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini \
&& echo 'xdebug.max_nesting_level=1000' >> $PHP_CONFIG_DIR/conf.d/xdebug.ini
WORKDIR /var/www/html
And here are my configs in PHPStorm:
I tried to change XDEBUG_CONFIG: remote_host=192.168.0.92 to XDEBUG_CONFIG: remote_host=host.docker.internal but it does not help. Also I can reach 192.168.0.92:8090 by curl from inside docker container successfully.
Does anyone have an idea how to fix this issue?
I have installed docker on ubuntu and mac os. "docker-composer up" command works as expected on ubuntu and mac.
But on windows 8, I have installed docker toolbox and run "docker-compose up" command. I'm getting error while creating php-container.
Below is the screenshot of error:
Below is the docker-compose.yml file
version: "3.2"
services:
php:
build: './php/'
container_name: php-container
networks:
- backend
volumes:
- ./code/:/var/www/html/
- ./php/config/php.ini:/usr/local/etc/php/conf.d/php.ini
- ./php/config/mcrypt.so:/usr/local/lib/php/extensions/no-debug-non-zts-20151012/mcrypt.so
links:
- redis:redis
nginx:
container_name: nginx-container
image: nginx:latest
depends_on:
- php
- mysql
ports:
- "80:80"
networks:
- frontend
- backend
volumes:
- ./code/:/var/www/html/
- ./site.conf:/etc/nginx/conf.d/default.conf
links:
- php
mysql:
image: mysql:5.6.40
container_name: mysql-container
networks:
- backend
environment:
- MYSQL_ROOT_PASSWORD=password
volumes:
- /var/lib/postgresql/data
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin-container
networks:
- backend
depends_on:
- mysql
links:
- mysql:mysql
ports:
- 8088:80
environment:
PMA_HOST: mysql
MYSQL_USERNAME: abcxyz
MYSQL_ROOT_PASSWORD: 321654987
networks:
frontend:
backend:
Below is the dockerfile for php
FROM php:7.0.32-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install mysqli
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
RUN apt-get -qq update && apt-get -qq -y install \
automake \
cmake \
g++ \
git \
libicu-dev \
libmagickwand-dev \
libpng-dev \
librabbitmq-dev \
libreadline-dev \
pkg-config \
ssh-client \
supervisor \
zlib1g-dev \
&& docker-php-ext-install \
bcmath \
gd \
intl \
opcache \
pdo_mysql \
sockets \
zip \
&& git clone git://github.com/alanxz/rabbitmq-c.git \
&& cd rabbitmq-c \
&& mkdir build && cd build \
&& cmake -DENABLE_SSL_SUPPORT=OFF .. \
&& cmake --build . --target install \
&& pecl install amqp imagick xdebug igbinary \
&& docker-php-ext-enable amqp imagick xdebug igbinary \
&& version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire /usr/bin/blackfire \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN apt-get install -y libxslt-dev
RUN apt-get install -y zlibc
RUN docker-php-ext-install xsl
RUN curl -s https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
Same error here...
In my case in the docker-compose.yml file
apache:
build: '.\apache\'
container_name: apache-container
depends_on:
- php
- mysql
networks:
- frontend
- backend
ports:
- "80:80"
volumes:
- .\public_html\:/var/www/html/
- .\apache\demo.apache.conf:/usr/local/apache2/conf/demo.apache.conf
- .\apache\custom.conf:/usr/local/apache2/conf/test.conf
In the last line - .\apache\custom.conf:/usr/local/apache2/conf/test.conf i'm copying custom conf to test conf in docker. which is working as expected.
But when I change the test.conf to httpd.conf and run docker-compose up , the same error occur as shown in above screenshot in the question.
Error:
Error screenshot
So, If I check files on apache container, I can see test.conf file also there is httpd.conf file, but when I trying to replace httpd.conf file it is showing error.