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.
Related
i am currently trying to run my Website in a Docker container using mysql and php with apache.
Docker-Compose:
version: '3.7'
services:
mysql:
image: mysql:latest
container_name: mysql
restart: always
environment:
//Database configuration variables
volumes:
- ./data/mysql/database:/var/lib/mysql
webserver:
image: php:7.4.12-apache
depends_on:
- mysql
restart: always
volumes:
- ./data/webserver:/var/www/html/
ports:
- 8888:80
command: bash -c "docker-php-ext-install mysqli && kill -HUP 1"
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin:latest
container_name: phpmyadmin
links:
- mysql:db
restart: always
ports:
- 8889:80
volumes:
- /sessions
The problem began after i added the command-block to the webserver-container. Without it, the container runs perfectly and i can access the website. But with the command, the container gets stuck in a boot-loop and it seems that it tries to run the command over and over. At least thats what i guess after looking at the log of the webserver container.
However when i use docker exec -it *webserver* bash and run the installation command directly in the container, it works perfectly. I then restart apache with kill -HUP 1 and the Website works as intended. Does anyone know what the problem is here?
Have you tried doing the install and apache restart inside a Dockerfile instead?
Something like:
FROM php:7.4.12-apache
RUN apt-get clean && apt-get update && apt-get install -y php7.4-mysqli;
RUN service apache2 restart;
Then your docker-compose could be:
[...]
webserver:
build:
context: .
dockerfile: docker/webserver/Dockerfile
depends_on:
- mysql
restart: always
volumes:
- ./data/webserver:/var/www/html/
ports:
- 8888:80
[...]
I have two containers PHP and nginx linked between them and i want that nginx container run PHP from php container. Now it's running PHP from my host machine. How can i fix that. Bellow is my docker-compose.yml file:
> version: '3'
> services:
> nginx:
> image: nginx:alpine
> volumes:
> - ./app:/app
> - ./nginx-config/:/etc/nginx/conf.d/
> ports:
> - 80:80
> depends_on:
> - php
> php:
> image: php:7.3-fpm-alpine
> volumes:
> - ./app:/app
You can look into dockerize-nginx-php docker-compose file, it supports both build time code for php and nginx and also support run code from mounting host volumes.
git clone https://github.com/Adiii717/dockerize-nginx-php.git
cd dockerize-nginx-php;
docker-compose -f docker-compose-buildtime.yml build
docker-compose -f docker-compose-buildtime.yml up
docker-compose.yml
version: '3'
services:
nginx:
build:
context: .
dockerfile: Dockerfile.nginx
image: nginxbuild_time
ports:
- 80:80
depends_on:
- php
php:
build:
context: .
dockerfile: Dockerfile.php
image: php
dockerfile.php
FROM php:7.3-fpm-alpine
WORKDIR /app
COPY app /app
Dockerfile.nginx
FROM nginx
COPY nginx-config /etc/nginx/conf.d/
COPY app /app
So #Ahmed resolves the issue by installing composer within container.
The problem is to install composer under php container. So i added a command to install composer in the DockerFile of PHP. Thanks for your support!
I've the following docker-compose file, and need some help with PHP composer part commented below:
version: '3'
services:
proxy:
image: jwilder/nginx-proxy
container_name: proxy
ports:
- '80:80'
- '443:443'
volumes:
- './certs:/etc/nginx/certs'
- '/var/run/docker.sock:/tmp/docker.sock:ro'
restart: always
web:
image: 'nginx:latest'
container_name: nginx
volumes:
- './volume1:/volume1'
- './volume2:/volume2'
- './volume3:/volume3'
- './site.conf:/etc/nginx/conf.d/site.conf'
environment:
- 'VIRTUAL_HOST=host1.local,host2.local,host3.local'
restart: always
php:
build: .
container_name: php
volumes:
- './volume1:/volume1'
- './volume2:/volume2'
- './volume3:/volume3'
restart: always
# Start How TODO this?
composer:
image: 'composer:latest'
container_name: composer
command: install
volumes:
- './volume1:/app'
- './volume2:/app'
- './volume3:/app'
# End HOW TODO this?
db:
image: mariadb
container_name: mariadb
ports:
- '3306:3306'
environment:
- MYSQL_ROOT_PASSWORD=toor
volumes:
- './db:/var/lib/mysql'
restart: always
pma:
image: phpmyadmin/phpmyadmin
container_name: pma
environment:
- PMA_ARBITRARY=1
- 'PMA_ABSOLUTE_URI=https://pma.local/'
- VIRTUAL_HOST=pma.local
restart: always
I've multiple app that needs to use composer, but I can't overwrite /app folder inside the composer container. Should I write a Dockerfile inside each single app folder? I don't want to specify the full path of PHP app inside the docker-compose, because I can have multiple version of an app (like 1.0, 2.0, ecc.ecc.).
Instead of putting the Composer configuration in your Docker Compose file, you should probably just run it once for each PHP app before you run the system.
docker run --rm -v $(pwd)/volume1:/app composer:latest install
This will run composer and bind the directory to your host filesystem so that the vendor folder will be available.
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/
I have a LEMP stack which is built by this docker-compose file:
cadvisor:
image: google/cadvisor:latest
container_name: lemp_cadvisor
ports:
- "8080:8080"
volumes:
- "/:/rootfs:ro"
- "/var/run:/var/run:rw"
- "/sys:/sys:ro"
- "/var/lib/docker/:/var/lib/docker:ro"
base:
build: ./base
container_name: lemp_base
volumes:
- /home/core/server-lemp/www/:/var/www/:rw
phpmyadmin:
build: ./phpmyadmin
container_name: lemp_phpmyadmin
links:
- base
volumes:
- /var/www/phpmyadmin
- ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
mariadb:
build: ./mariadb
container_name: lemp_mariadb
environment:
- MYSQL_ROOT_PASSWORD=pwd
links:
- base
volumes:
- /var/run/mysqld
- /home/core/server-lemp/mariadb/:/var/lib/mysql/:rw
- ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
ffmpeg:
build: ./ffmpeg
container_name: lemp_ffmpeg
links:
- base
volumes:
- /usr/ffmpeg
cron:
build: ./cron
container_name: lemp_cron
links:
- base
volumes:
- /etc/cron.weekly
- /etc/cron.d
- /etc/cron.hourly
- /etc/cron.daily
- /etc/cron.monthly
php:
build: ./php
container_name: lemp_php
links:
- base
volumes:
- /var/run/php-fpm
- ./php/usr/local/php7/etc/php-fpm.conf:/usr/local/php7/etc/php-fpm.conf:ro
- ./php/usr/local/php7/etc/php.ini:/usr/local/php7/etc/php.ini:ro
- ./php/usr/local/php7/etc/php-fpm.d/www.conf:/usr/local/php7/etc/php-fpm.d/www.conf:ro
volumes_from:
- base
- phpmyadmin
- mariadb
- ffmpeg
- cron
nginx:
build: ./nginx
container_name: lemp_nginx
links:
- base
ports:
- "80:80"
- "443:443"
volumes:
- /var/cache/nginx
- ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
volumes_from:
- php
My ./cron/Dockerfile looks like this:
# Lanti/lempCron
#
# VERSION 1.0.0
FROM lemp_base:latest
MAINTAINER XY <info#domain.com>
LABEL Description="Cron" Vendor="XY" Version="1.0"
RUN apt-get -y update && apt-get -y dist-upgrade \
&& apt-get -y install \
cron
RUN rm -rf /var/lib/apt/lists/*
CMD ["cron", "-f"]
When in a Wordpress install I inspecting running cron jobs with WP Crontrol plugin, I got the following error message:
There was a problem spawning a call to the WP-Cron system on your site.
This means WP-Cron events on your site may not work. The problem was:
Failed to connect to 127.0.0.1 port 80: Connection refused
I assume because of the same error that causing this, the Cache Purge option in the Nginx-helper plugin also not working.
Wordpress is presumably running in your 'php' container, and the "wp-cron" function is presumably working there. Although it is "cron-like", it is actually part of Wordpress.
You have defined no ports for your `php' container, so it appears that you need to update your Docker networking so that wp-contain can access port 80 on the correct host.