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
[...]
Related
I have a docker-compose environment setup.
But inside service "Lumen" im trying to make a CURL request to the service itself.
However, the container can't access itself from localhost:8000 OR lumen:8000??
When I call lumen:8000 from the service it just never returns a response and just keeps loading ( And the curl request is to a different url so no infinite loop )
In my Laravel controller I found the protocal, host and port to be: http://lumen:8000
I seems like Laravel can't connect to itself, which I really need for my project.
I can connect to the Laravel from my own computer through localhost, but I need the Laravel to call it self.
Error message from Laravel controller after doing a CURL request:
Failed to connect to localhost port 8000 after 0 ms: Connection refused
Changing host to "lumen" just makes the request load infinite. No matter what page I try to connect to.
Docker-compose file:
version: "3.5"
services:
lumen:
expose:
- "8000"
ports:
- "8000:8000"
volumes:
- ./server:/var/www/html
- ./server/vendor:/var/www/html/vendor/
build:
context: server
dockerfile: Dockerfile
command: php -S lumen:8000 -t public
restart: always
privileged: true
depends_on:
- database
networks:
- database
frontend:
build:
context: client
dockerfile: Dockerfile
volumes:
- ./client/src:/app/src
ports:
- 3000:3000
stdin_open: true
#restart: always
networks:
- database
# Database Service (Mysql)
database:
image: mysql:latest
container_name: blogmoda_mysql
environment:
MYSQL_DATABASE: blogmoda-app
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci','--default-authentication-plugin=mysql_native_password']
ports:
- "127.0.0.1:3306:3306"
volumes:
- db-data:/var/lib/mysql
networks:
- database
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: dev_phpmyadmin
links:
- database
environment:
PMA_HOST: database
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
depends_on:
- database
ports:
- 9001:80
networks:
- database
volumes:
db-data:
# Networks to be created to facilitate communication between containers
networks:
database:
Server dockerfile:
FROM php:8.1-fpm-alpine
RUN apk update && apk add bash
RUN apk add chromium
RUN apk add --no-cache zip libzip-dev
RUN docker-php-ext-configure zip
RUN docker-php-ext-install zip
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install opcache
WORKDIR /var/www/html/
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
COPY . .
RUN composer install --ignore-platform-req=ext-zip --ignore-platform-reqs
I believe localhost should work. Assuming curl is installed in lumen, in your compose file under the lumen service can you try changing your command
command: php -S lumen:8000 -t public
to a direct curl via bash as
command: sh -c "curl -s localhost:8000"
Then check the logs of the lumen container to see whether or not the curl ran successfully.
Try 0.0.0.0:8000 instead localhost:8000. It works for localhost too
I have this docker-compose configuration:
mysql:
image: mariadb:latest
container_name: ${APP_NAME}-mysql
command: --lower_case_table_names=2
volumes:
- './data/db:/var/lib/mysql:delegated'
environment:
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
- MYSQL_DATABASE=${DB_NAME}
restart: unless-stopped
ports:
- '3307:3306'
networks:
- app
wordpress:
build:
context: .
dockerfile: Dockerfile
container_name: ${APP_NAME}-wordpress
volumes:
- ./src:/var/www/html:rw,cached
- ./config/php.ini:/usr/local/etc/php/conf.d/php.ini
environment:
XDEBUG_ENABLED: 1
XDEBUG_CONFIG: remote_host=host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
env_file:
- src/.env
depends_on:
- mysql
links:
- mysql:db
restart: always
networks:
- app
My Docker file looks like the following (after installing wordpress and mariadb)
# Install wp-cli
RUN apt-get update && apt-get install -y sudo less mariadb-client
RUN curl -o /bin/wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
RUN chmod +x /bin/wp-cli.phar
RUN cd /bin && mv wp-cli.phar wp
RUN mkdir -p /var/www/.wp-cli/cache && chown www-data:www-data /var/www/.wp-cli/cache
When I access the wordpress container I correctly see wp cli installed since I get this:
As you can see when I run the help command with --allow-root it doesn't print anything. Any suggestions?
i have a docker-compose.yml that looks like this:
webserver:
build: ./_docker/php
ports:
- 80:80
links:
- mysql
volumes_from:
- app
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USER}"
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PW}"
MYSQL_PASSWORD: "${DB_PW}"
volumes:
- ./_docker/data/db:/docker-entrypoint-initdb.d
volumes_from:
- data
data:
image: mysql:5.7
volumes:
- /var/lib/mysql
command: "true"
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
links:
- mysql
environment:
PMA_HOST: mysql
app:
image: tianon/true
volumes:
- .:/var/www/public_html
Dockerfile looks like this:
FROM php:7.0-apache
#php:7.2.2-apache
#php:5.6.33-apache
COPY php.ini /usr/local/etc/php/
COPY 000-default.conf /etc/apache2/sites-available/
RUN a2enmod rewrite
RUN a2enmod expires
RUN a2enmod headers
RUN apt-get update
RUN apt-get install -y zlib1g-dev libxml2-dev libfreetype6-dev libjpeg62-turbo-dev libmcrypt-dev libpng12.0 imagemagick
RUN docker-php-ext-install mysqli zip soap
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
# Install opcache
RUN docker-php-ext-install opcache
and the php ini like this:
max_input_vars = 1500
max_execution_time = 300
post_max_size=50M
upload_max_filesize=50M
when i start the container i have my webserver located on http://localhost.
i put an index.php with a phpinfo(); inside it and it shows, that the php.ini works.
When i open http://localhost:8080 and login to PMA it shows me that my upload limit i set to 2048KiB.
Where can i change this?
Thanks in advance!
Use like this UPLOAD_LIMIT env in docker. This is from my docker-compose.yml. Default value for UPLOAD_LIMIT is 2048K which is 2048KiB. Setting value to 300M increases it to 300MiB.
Reference: https://github.com/phpmyadmin/docker#environment-variables-summary
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'php7.3-phpmyadmin'
restart: 'always'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
UPLOAD_LIMIT: 300M
ports:
- '8082:80'
volumes:
- /sessions
I implemented UPLOAD_LIMIT ENV variable in
https://github.com/phpmyadmin/docker/pull/261/files#diff-80edf79b0f382a3c6e871ac209ffd6abR57
you need to use UPLOAD_LIMIT inside enviroment, and you need to specify values with = sign, like example: UPLOAD_LIMIT=300M
version: '3.1'
services:
db:
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: somerandompasswordgenerated
ports:
- 3306:3306
phpmyadmin:
image: phpmyadmin
restart: always
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
- UPLOAD_LIMIT=300M
UPLOAD_LIMIT: 500M
mariadb:
image: mariadb:latest
container_name: w-mariadb
restart: always
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: db_name
MYSQL_USER: root
MYSQL_PASSWORD: db_password
MYSQL_ROOT_PASSWORD: db_password
volumes:
- 'w-mariadb:/var/lib/mysql'
networks:
- w-network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: w-phpmyadmin
links:
- mariadb
environment:
MYSQL_ROOT_PASSWORD: db_password
PMA_HOST: mariadb
UPLOAD_LIMIT: 500M
restart: always
ports:
- '8383:80'
networks:
- w-network
In my case I couldn't fix it with UPLOAD_LIMIT, so without further debugging I needed a quick solution even if it's temporary:
open phpmyadmin container terminal: docker exec -it container_name bash
If you don't have vim or nano editor install one: apt-get update, apt-get install vim
create config file: vi /usr/local/php/conf.d/myconf.ini
with this content: post_max_size=50M upload_max_filesize=50M
restart container
Remember these changes will be gone when container is recreated, it's just a temporary solution. Try working with UPLOAD_LIMIT as suggested in previous answer.
UPDATE
Tried again with setting upload_limit environment, but still without luck, so found another solution:
created a file say uploads.ini with this content:
post_max_size=50M
upload_max_filesize=50M
and link it to container volume :
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql:db
ports:
- 8084:80
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/php-phpmyadmin.ini
environment:
MYSQL_ROOT_PASSWORD: something
#UPLOAD_LIMIT: 3000000000 <-- didn't work
the following worked very well.
My docker-compose.yml contains this:
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: some-name
env_file:
- phpmyadmin.env
depends_on:
- mariadb
volumes:
The following entry was added to the phpmyadmin.env: UPLOAD_LIMIT=256MB
The larger number (Maximal: 256MiB) showed up right after the container was brought down and was back up again.
If you want to install from phpmyadmin docker image and with docker run, you can exec this.
docker run --name your-image-name -d --link mysql-docker:db --env "UPLOAD_LIMIT=256M" phpmyadmin
This works for me and enable upload to 256MB SQL file.
I edit this file :
/usr/local/etc/php/conf.d/phpmyadmin-misc.ini
and set new values :
post_max_size=64M
upload_max_filesize=64M
It works fine.
In linux I build a blog application that is based on mysql, apache2 and php. But I use some python for it. The python is for adapting python Pygments that is described there https://davidwalsh.name/pygments-php-wordpress .
I prepared docker compose stage that works fine but python does not work in it. How to add python to docker compose?
Here are my files:
root#debian:/usr/local/share/a22php7m55# cat docker-compose.yml
version: "2.1"
services:
apachephp:
build: ./a22php7/
ports:
- 8888:80
volumes:
- "/etc/passwd:/etc/passwd:ro"
- "/etc/group:/etc/group:ro"
- "${PROJECT_ROOT}:/var/www/html"
networks:
- database
- server
depends_on:
- mysql
container_name: ap47
mysql:
image: mariadb:5.5
volumes:
- ${MYSQL_DATA}:/var/lib/mysql
networks:
- database
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: "${MYSQL_NAME}"
MYSQL_USER: "${MYSQL_USERNAME}"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
container_name: maria47
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8080:80
networks:
- database
depends_on:
- mysql
environment:
PMA_HOST: mysql
container_name: pma47
volumes:
mariadb:
networks:
database:
server:
root#debian:/usr/local/share/a22php7m55# cat a22php7/
root#debian:/usr/local/share/a22php7m55# cat a22php7/Dockerfile
FROM php:7.1.3-apache
RUN docker-php-ext-install pdo pdo_mysql
root#debian:/usr/local/share/a22php7m55#
Looking at the base image for php:7.1.3-apache we see it's built on debian:jessie so we can install python, pip and pygments by adding these lines to your Dockerfile:
RUN apt-get update && apt-get install -y python python-pip
RUN pip install pygments
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.