Enable/Disable xDebug through Docker-Compose, is it possible? - docker

I have the following Dockerfile:
FROM php:7.2-apache
RUN apt-get update && apt-get install -y \
zlib1g-dev \
git \
unzip \
&& rm -rf /var/lib/apt/lists/ \
&& docker-php-ext-install zip pdo_mysql bcmath \
&& a2enmod rewrite \
&& pecl install xdebug-2.9.0 redis \
&& docker-php-ext-enable xdebug redis \
&& mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
&& mv /var/www/html /var/www \
&& chown -R www-data:www-data /var/www/ \
&& ln -s /usr/local/bin/php /usr/bin/php
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer
WORKDIR /var/www/drm-case
CMD ["docker/apache/bootstrap.sh"]
And this is the docker-compose.yml file that uses the previous Dockerfile to build the containers (not all the time though):
version: "2.4"
services:
case-v2-apache:
container_name: local-dev
image: local-dev:1.6 # increase this number when changing the Dockerfile
depends_on:
mysql-server:
condition: service_healthy
volumes:
- ${LOCAL_PATH}:/var/www:delegated
- ${LOCAL_PATH}/docker/apache/conf.d:/usr/local/etc/php/conf.d
- ${LOCAL_PATH}/docker/apache/conf-enabled/servername.conf:/etc/apache2/conf-enabled/servername.conf
- ${LOCAL_PATH}/docker/apache/sites-available/000-default.conf:/etc/apache2/sites-available/000-default.conf
ports:
- "8009:80"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
build:
context: ${LOCAL_PATH:-./local-dev}
dockerfile: docker/apache/Dockerfile
networks:
- main
environment:
- VIRTUAL_HOST=local-dev.localhost
- COMPOSER_MEMORY_LIMIT=-1
- COMPOSER_AUTH=${COMPOSER_AUTH}
- COMPOSER_ALLOW_SUPERUSER=1
- PHP_IDE_CONFIG=serverName=local-dev
One of the files being copied in this line: ${LOCAL_PATH}/docker/apache/conf.d:/usr/local/etc/php/conf.d is xdebug related meaning is the one enabling and setting up the extension.
Wonder if there is a way to tell Docker by using ARG or ENV variables to enable/disable xDebug while starting the container? Has anyone tried such thing before? If so can you help me with some ideas?

You could simply move/rename the xdebug conf file based on a build arg…
FROM php:7.2-apache
RUN apt-get update && apt-get install -y \
zlib1g-dev \
git \
unzip \
&& rm -rf /var/lib/apt/lists/ \
&& docker-php-ext-install zip pdo_mysql bcmath \
&& a2enmod rewrite \
&& pecl install xdebug-2.9.0 redis \
&& docker-php-ext-enable xdebug redis \
&& mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
&& mv /var/www/html /var/www \
&& chown -R www-data:www-data /var/www/ \
&& ln -s /usr/local/bin/php /usr/bin/php
COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer
RUN if [[ "$DISABLE_XDEBUG" == "1" ]] ; then mv "$PHP_INI_DIR/conf.d/xdebug.ini" "$PHP_INI_DIR/conf.d/xdebug.ini.disabled"
WORKDIR /var/www/drm-case
CMD ["docker/apache/bootstrap.sh"]
… or something like that?

Related

Error no such file or directory when docker compose build

$docker-compose build
mv: cannot stat '/root/.symfony/bin/symfony': No such file or directory
ERROR: Service 'www_symfony_colcot' failed to build: The command '/bin/sh -c echo "ServerName localhost" >> /etc/apache2/apache2.conf && apt-get
Normaly auto generated by docker-compose.yml
docker-compose.yml :
version: "3.5"
services:
db_symfony_colcot:
image: mariadb:10.5.13
container_name: db_symfony_colcot
command: [ "--default-authentication-plugin=mysql_native_password" ]
restart: always
environment:
MYSQL_ROOT_PASSWORD: gsbgenerique
MYSQL_DATABASE: colcot
MYSQL_USER: gestionnaire
MYSQL_PASSWORD: gsbgenerique
volumes:
- ./initSQL/:/docker-entrypoint-initdb.d/
- "./datamysql-colcot:/var/lib/mysql"
ports:
- "3311:3306"
networks:
- dev-sym
www_symfony_colcot:
build: php
container_name: www_symfony_colcot
ports:
- "8094:80"
user: 0:0
volumes:
- ./php/vhosts:/etc/apache2/sites-enabled
- /home/marc/Desktop/colcot/colcot-2022/Colcot/:/var/www
restart: always
networks:
- dev-sym
networks:
dev-sym:
volumes:
db-data:
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 \
&& useradd -m symfony -u 1001 \
\
&& docker-php-ext-configure \
intl \
&& docker-php-ext-install \
pdo pdo_mysql opcache intl zip calendar dom mbstring gd xsl \
\
&& pecl install apcu && docker-php-ext-enable apcu
WORKDIR /var/www/
Error caused by line :
&& mv /root/.symfony/bin/symfony /usr/local/bin \
How can i solve this error please. Btw im beginner with docker but this project was working since 5 month ago.
Already try :
Change mariadb version
All php version ( from 5.6 to 8 )
Change dockercompose version
Result : Still not working and same error
The command you are using to install symfony:
curl -sS https://get.symfony.com/cli/installer | bash
Is installing Symfony version 5. The files are located in symfony5 folder (notice the 5):
The Symfony CLI was installed successfully!
Use it as a local file:
/root/.symfony5/bin/symfony
So instead of running mv /root/.symfony/bin/symfony /usr/local/bin (.symfony folder does not exist), you should run:
mv /root/.symfony5/bin/symfony /usr/local/bin
By the way, as of 2022, using this script seems not to be the recommended method anymore: see https://symfony.com/download.
For info, the commit who changes the folder in the script from .symfony to .symfony5 is this one: https://github.com/symfony-cli/symfony-cli/commit/5301ebfa8f5918cae7fa0bf63c86f84dbd70f599.
I will add that in order to understand whether version 5 has changed to some other, you can look at the installer file (https://get.symfony.com/cli/installer) itself. Now (at the time of writing this comment) there is such information:
CLI_CONFIG_DIR=".symfony5"

Running Puppeter inside Docker Container

I'm trying to run my application in container, this is my Dockerfile:
FROM node:12-slim
WORKDIR /app
# Install Chrome
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
RUN yarn add puppeteer \
# Add user so we don't need --no-sandbox.
# same layer as npm install to keep re-chowned files from using up several hundred MBs more space
&& groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /node_modules
USER pptruser
CMD ["google-chrome-stable"]
COPY package.json ./
RUN yarn install
COPY . .
EXPOSE 3000
CMD ["yarn","start"]
I wrap my puppeter function with try catch, and when I try to run the application the catch is trigged:
try{
...
}catch(error){
Running as root without --no-sandbox is not supported. See https://crbug.com/638180.\n\n\nTROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md\n"}]
}
I add this arg const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
My docker-compose:
version: '3.7'
services:
api:
build: .
ports:
- "3000:3000"
cap_add:
- SYS_ADMIN
init: true
container_name: web_scraping
I'm running the docker-compose, none erro appers while it is running, only when I call the api the catch is trigged
follow this Node.js + Puppeteer on Docker, No usable sandbox answer, I got this
docker-compose:
version: '3.7'
services:
api:
build: .
ports:
- "3000:3000"
container_name: web_scraping
Dockerfile:
FROM node:12
RUN apt-get update \
&& apt-get install -y wget gnupg ca-certificates \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
# We install Chrome to get all the OS level dependencies, but Chrome itself
# is not actually used as it's packaged in the node puppeteer library.
# Alternatively, we could could include the entire dep list ourselves
# (https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
# but that seems too easy to get out of date.
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/* \
&& wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
&& chmod +x /usr/sbin/wait-for-it.sh
WORKDIR /app
COPY package.json ./
RUN yarn install
COPY . .
EXPOSE 3000
CMD ["yarn","start"]
And Add this args in launch instance:
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
});

PHP is unable to see env var when runing in docker

I have this docker-compose config.
The "app" is a PHP application. As you can see, 3 env vars are passed to the container.
However, after docker-compose up, PHP doesn't see these. They are not returned by getenv() and they cannot be found $_ENV either.
What's wrong here?
version: '3.4'
services:
db:
image: postgres:11.0
restart: always
environment:
POSTGRES_PASSWORD: testuser
POSTGRES_USER: test
POSTGRES_DB: db
volumes:
- /data/db
redis:
image: redis:latest
restart: always
volumes:
- /data/redis
app:
build:
context: .
dockerfile: Dockerfile
environment:
- DATABASE_URL=postgresql://db:5432/db
- REDIS_URL=tcp://redis:6379?database=1
- NODE_ENV=development
ports:
- '80:80'
volumes:
- '${BASEDIR}:/var/www/some'
Here is my Dockerfile:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
software-properties-common \
apt-utils \
tzdata \
locales
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update
RUN locale-gen en_US.UTF-8
RUN echo "Europe/Budapest" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get -y update && apt-get -y install \
libglu1-mesa \
less \
vim \
nginx \
php7.4 \
php7.4-fpm \
php7.4-cli \
php7.4-common \
php7.4-curl \
php-deepcopy \
php7.4-gd \
php7.4-mbstring \
php7.4-pgsql \
php7.4-soap \
php7.4-xdebug \
php7.4-zip \
php7.4-xml \
phpunit \
npm && npm i -g npm
ENV NGINX_RUN_USER www-data
ENV NGINX_RUN_GROUP www-data
ENV NGINX_LOG_DIR /var/log/nginx
ENV NGINX_LOCK_DIR /var/lock/nginx
ENV NGINX_PID_FILE /run/nginx.pid
RUN mkdir www
RUN mkdir -p /var/www/dbv.local/html
RUN chmod -R 755 /var/www/dbv.local
COPY ./php.ini /etc/php/7.4/fpm/php.ini
COPY ./dbv.local /etc/nginx/sites-available/dbv.local
COPY ./lib/aspose_php.so /usr/lib/php/20190902
COPY ./lib/libaspose_cpp_clang3_libstdcpp.so /usr/lib/libaspose_cpp_clang3_libstdcpp.so
COPY ./lib/libAspose.Slides_clang3_libstdcpp.so /usr/lib/libAspose.Slides_clang3_libstdcpp.so
COPY ./lib/libphpcpp.so.2.2 /usr/lib/libphpcpp.so.2.2
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN ln -s /etc/nginx/sites-available/dbv.local /etc/nginx/sites-enabled/
ADD ./xdebug.ini /etc/php/7.4/mods-available/xdebug.ini
ADD ./aspose_php.ini /etc/php/7.4/mods-available/aspose_php.ini
ADD ./start.sh /root/start.sh
RUN ln -s /etc/php/7.4/mods-available/xdebug.ini /etc/php/7.4/mods-available/20-xdebug.ini
RUN ln -s /etc/php/7.4/mods-available/aspose_php.ini /etc/php/7.4/fpm/conf.d/aspose_php.ini
RUN ln -s /etc/php/7.4/mods-available/aspose_php.ini /etc/php/7.4/cli/conf.d/aspose_php.ini
RUN rm -rf /var/lib/apt/lists/*
RUN apt-get clean
CMD ["/root/start.sh"]
EXPOSE 80 9000 5432
Edit:
start.sh is just a one liner
service php7.4-fpm start && nginx
Ubuntu 18 is necessary. I could use an official Nginx image though. Maybe that's the issue?

what should I write on dockerfile for nginx and php:7.0-fpm?

I want to work on nginx server and I use php:7.0-fpm
what should I write on dockerfile especially where begining from?
This is my docker-compose.yml
version: '3'
services:
php:
build:
context: .
dockerfile: Dockerfile_php
image: php-fpm71:phalcon
networks:
- app
ports:
- "9000:9000"
volumes:
- ./www:/var/www/html
- ./conf/php/php.ini:/usr/local/etc/php/php.ini
- ./shared:/shared
nginx:
build:
context: .
dockerfile: Dockerfile_nginx
networks:
- app
depends_on:
- php
ports:
- "80:80"
volumes:
- ./www:/var/www/html
- ./conf/nginx/conf.d:/etc/nginx/conf.d
- ./logs/nginx:/var/log/nginx
- ./shared:/shared
mysql:
networks:
- app
depends_on:
- php
image: mysql:latest
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./data/mysql:/var/lib/mysql
- ./shared:/shared
networks:
app:
Dockerfile_nginx
FROM nginx:latest
MAINTAINER Yakup Arslan <arslan.yakup#hotmail.com>
RUN apt-get update -y
RUN apt-get install -y \
vim
RUN apt-get autoremove -y && \
apt-get autoclean -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN rm -rf /var/log /var/cache
Dockerfile_php
#
# PHP-7.1 Phalcon Support
#
#
# Pull base image
FROM php:7.1-fpm
MAINTAINER Yakup Arslan <arslan.yakup#hotmail.com>
RUN curl -O https://codeload.github.com/phalcon/cphalcon/tar.gz/v3.1.2
RUN tar xvzf v3.1.2
RUN cd cphalcon-3.1.2/build && ./install
RUN cd ../../ && rm -Rf cphalcon-3.1.2 && rm -Rf v3.1.2
RUN echo extension=phalcon.so > /usr/local/etc/php/conf.d/phalcon.ini
RUN apt-get update -y
RUN apt-get install -y \
git \
zip \
unzip \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev
RUN git clone https://github.com/phalcon/phalcon-devtools.git /usr/local/lib/phalcon-devtools && \
ln -svf /usr/local/lib/phalcon-devtools/phalcon.php /usr/local/bin/phalcon && \
chmod ugo+x /usr/local/bin/phalcon
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) mysqli \
pdo_mysql \
bcmath \
gd
RUN apt-get autoremove -y && \
apt-get autoclean -y && \
apt-get clean -y && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /etc/php5 /etc/php/5* /usr/lib/php/20121212 /usr/lib/php/20131226
RUN rm -rf /var/log /var/cache

Why are environment variables not being set inside of my docker container?

I have the following in my docker-compose.yml:
php:
build:
args:
http_proxy:
https_proxy:
no_proxy:
context: ./vm-images/php
environment:
http_proxy:
https_proxy:
no_proxy:
CURRENT_ENVIRONMENT: DOCKER
container_name: php
ports:
- "9000:9000"
depends_on:
- mysql
links:
- mysql:mysql
logging:
driver: "json-file"
volumes:
- /var/www/:/var/www/
My DOCKERFILE has the following:
FROM ubuntu:latest
RUN locale-gen en_US.UTF-8 && \
export LANG=en_US.UTF-8 && \
export LC_ALL=en_US.UTF-8
RUN apt-get update && \
apt-get install -y --reinstall ca-certificates
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends \
software-properties-common python-software-properties
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends \
git-core \
libjpeg-progs \
mysql-client \
optipng \
php5.6 \
php5.6-curl \
php5.6-intl \
php5.6-fpm \
php5.6-gd \
php5.6-mcrypt \
php5.6-mysqli \
php5.6-pdo \
php5.6-xdebug \
php5.6-xml \
php5.6-zip
RUN rm -r /var/lib/apt/lists/*
RUN rm -r /var/cache/apt/*
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
php -r "unlink('composer-setup.php');"
RUN mkdir -p /run/php && chown www-data:www-data /run/php
COPY files/etc/php/fpm/php-fpm.conf /etc/php/5.6/fpm/php-fpm.conf
COPY files/etc/php/fpm/pool.d/www.conf /etc/php/5.6/fpm/pool.d/www.conf
COPY files/etc/php/fpm/php.ini /etc/php/5.6/fpm/php.ini
COPY files/etc/php/cli/php.ini /etc/php/5.6/cli/php.ini
COPY files/etc/php/mods-available/xdebug.ini /etc/php/5.6/mods-available/xdebug.ini
RUN phpenmod curl intl gd mcrypt mysqli pdo xdebug xml zip
CMD ["php-fpm5.6", "--nodaemonize", "--fpm-config", "/etc/php/5.6/fpm/php-fpm.conf"]
When I run docker-compose --verbose up -d I notice that there are no env vars passed in for my php container. I've verified that those env vars are set on my host, and they are passed in for all of my other containers without fail. Anyone have any ideas?
EDIT: Strangely enough, I've also noticed that /proc/$PID/environ (where $PID is the PID of the php container [obtained by running docker inspect --format "{{.State.Pid}}" php] on the host machine is empty.

Resources