I want to run php website with letsencrypt and nginx using docker-compose. But it doesn't work. I tried to use other simple web page (not php), like: index.html and it works.
My docker-compose file is based on this project: https://github.com/gilyes/docker-nginx-letsencrypt-sample/blob/master/docker-compose.yml.
Help me, please with php, thanks.
version: "2"
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- "80:80"
- "443:443"
volumes:
- "/etc/nginx/conf.d"
- "/etc/nginx/vhost.d"
- "./website:/usr/share/nginx/html"
- "./volumes/proxy/certs:/etc/nginx/certs:ro"
depends_on:
- fpm
nginx-gen:
restart: always
image: jwilder/docker-gen
container_name: nginx-gen
volumes:
- "/var/run/docker.sock:/tmp/docker.sock:ro"
- "./volumes/proxy/templates/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro"
volumes_from:
- nginx
entrypoint: /usr/local/bin/docker-gen -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
letsencrypt-nginx-proxy-companion:
restart: always
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt-nginx-proxy-companion
volumes_from:
- nginx
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./volumes/proxy/certs:/etc/nginx/certs:rw"
environment:
- NGINX_DOCKER_GEN_CONTAINER=nginx-gen
fpm:
restart: always
build: ./php-fpm
ports:
- "9000"
container_name: fpm-website
volumes:
- "./website:/usr/share/nginx/html" # folder with web-site
- "./php-fpm/php.ini-production.ini:/usr/local/etc/php/php.ini:ro"
environment:
- VIRTUAL_HOST=website.com
- LETSENCRYPT_HOST=website.com
- LETSENCRYPT_EMAIL=ser#website.com
Here is my Dockerfile for "fpm" container:
FROM php:7.3.2-fpm-alpine
RUN apk update; \
apk upgrade;
RUN docker-php-ext-install mysqli
When I try to open page, I have a message:
502 Bad Gateway
nginx/1.15.12
Related
It seems that when i run Docker compose up, docker is not reading from docker-compose.yml.
It seems like it is loading images from cache or i don't think where is finding them.
Bellow is my docker-compose.yml
version: '3'
services:
httpd:
image: httpd:latest
user: root
ports:
- "80:80" # Default Apache port (Default on PHP 7.4)
- "8073:8073" # PHP 7.3 Apache port
- "8074:8074" # PHP 7.4 Apache port
- "8081:8081" # PHP 8.1 Apache port
volumes:
- ./:/var/www/html/myApp/:rw
- ./dev/Docker/httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
restart: on-failure
container_name: httpd
networks:
- mb-frontend
php8.1-fpm:
build: ./dev/Docker/php-fpm/8.1
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php8.1-fpm
networks:
- mb-frontend
- mb-backend
php7.4-fpm:
build: ./dev/Docker/php-fpm/7.4
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.4-fpm
networks:
- mb-frontend
- mb-backend
php7.3-fpm:
build: ./dev/Docker/php-fpm/7.3
user: root
environment:
XDEBUG_ENABLED: 1
XDEBUG_REMOTE_HOST: host.docker.internal
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./:/var/www/html/myApp/:rw
restart: on-failure
container_name: php7.3-fpm
networks:
- mb-frontend
- mb-backend
db:
image: mariadb:10.3.5
environment:
MYSQL_ROOT_PASSWORD: myPassword
MYSQL_USER: dev
MYSQL_PASSWORD: myPassword
ports:
- "3306:3306"
volumes:
- /root/Bureau/mysql:/var/lib/mysql/:rw
- ./dev/Docker/mariadb/conf.d/:/etc/mysql/conf.d/:rw
- ./dev/Docker/mariadb/config/init.sql:/docker-entrypoint-initdb.d/init.sql
restart: on-failure
container_name: db
networks:
- mb-backend
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
volumes:
- /root/Bureau/phpmyadmin:/var/lib/mysql/
networks:
- mb-backend
depends_on:
- db
redis:
image: redis:6.2
container_name: redis
ports:
- "6379:6379"
networks:
- mb-backend
networks:
mb-frontend:
driver: bridge
mb-backend:
driver: bridge
I commented some images on docker-compose.yml but when i tape the command Docker compose up on terminal, all images even commented images are Up.
Can anyone help me how i force docker to read images from the edited docker-compose.yml
Good practice would be do use:
docker compose down
and then
docker compose up
UPDATE:
Next I would suggest to clean up your containers:
List all containers:
docker ps -a
Remove those you don't want because they might still be in the system
docker rm <CONTAINER ID/NAME>
How to Stop & Remove a running container by ID or Name?
The command is actually docker compose up.
The command docker-compose has been deprecated as of latest version. We can now use docker compose without the hyphen(-).
You can use docker-compose -f <path-to-compose-file> to pass in the compose file.
Example:
docker compose -f docker-compose.yml up
Reference documentation: https://docs.docker.com/compose/reference/
This is my docker-compose.yml
version: '3.9'
networks:
bedrock:
services:
web:
container_name: kawa-web
image: nginx:stable-alpine
volumes:
- ./:/var/www/html:delegated
- ./docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- 8080:80
depends_on:
- php
- mysql
networks:
- bedrock
php:
container_name: kawa-php
image: nanoninja/php-fpm:8.0
volumes:
- ./:/var/www/html
- ./docker/config/php.ini:/usr/local/etc/php/conf.d/php.ini
ports:
- 9000:9000
networks:
- bedrock
mysql:
container_name: kawa-db
image: mysql:8
volumes:
- ./docker/db:/var/lib/mysql:delegated
ports:
- 3306:3306
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
networks:
- bedrock
node:
container_name: kawa-node
build:
context: .
dockerfile: node.dockerfile
volumes:
- ./:/var/www/html
networks:
- bedrock
Content of node.dockerfile
FROM node:18-alpine
WORKDIR /var/www/html
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
When I run docker compose up -d it shows
failed to solve: error from sender: open /path/to/project/docker/db/#innodb_temp: permission denied
How can I fix this? Or any another way to run nodejs inside PHP container maybe?
When your Compose setup has:
services:
mysql:
volumes:
- ./docker/db:/var/lib/mysql:delegated
node:
build:
context: .
The MySQL data directory is in the ./docker/db directory. That's inside the . build-context directory of the Node application, so docker-compose build among other things sends the entire MySQL data to itself, and if the database is currently running, you could get lock or permission problems like this.
The best approach to work around this is to split your application into separate directories, and have each language component only build its own subdirectory.
$ ls -1F
data/
docker-compose.yml
js/
php/
static/
$ ls -1F js
Dockerfile
index.js
node_modules/
package.json
package-lock.json
# docker-compose.yml
version: '3.8'
services:
...
mysql:
image: mysql:8
volumes:
- ./data/db:/var/lib/mysql:delegated
ports:
- 3306:3306
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
node:
build: ./js
(Note that I've used the short syntax for build: to use the default Dockerfile in the context directory; I've removed unnecessary container_name: and networks: options, using the Compose-provided default network; and I've removed the volumes: that overwrite the image's content. Make sure ./js/Dockerfile has a CMD instruction that says how to start the container.)
Hello all Connections Greeting,
I am using this repository https://github.com/markshust/docker-magento for magento2 installation with docker.
I installed magento 2.3.3 and configured php 7.3 in docker file.
Problem is installation is completed without any error but, I am getting unable to connect after every new installation in browser.
Please help if you facing this same issue.
Thank you in advance.
docker-compose.yml file
# Mark Shust's Docker Configuration for Magento
# (https://github.com/markshust/docker-magento)
#
# Version 34.2.0
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-4
ports:
- "8000:80"
- "8443:443"
links:
- db
- phpfpm
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
phpfpm:
image: markoshust/magento-php:7.3-fpm-0
links:
- db
volumes: *appvolumes
db:
image: percona:5.7
command: --max_allowed_packet=64M
ports:
- "8080:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
redis:
image: redis:5.0-alpine
elasticsearch:
image: markoshust/magento-elasticsearch:7.6.2-2
ports:
- "9200:9200"
- "9300:9300"
environment:
- "discovery.type=single-node"
myadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: always
volumes:
- dbdata:/var/lib/mysql
ports:
- "8082:80"
depends_on:
- db
rabbitmq:
image: rabbitmq:3.7-management-alpine
ports:
- "15672:15672"
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq
# Disabling cron by default as it uses higher CPU, enable if needed
#cron:
# image: markoshust/magento-php:7.4-fpm-2
# user: root
# command: /usr/local/bin/cronstart
# tty: true
# links:
# - db
# volumes: *appvolumes
volumes:
appdata:
dbdata:
rabbitmqdata:
sockdata:
ssldata:
I am running below commands step by step
git clone https://github.com/markshust/docker-magento.git
cd docker-magento & curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
bin download 2.3.3 & then add host in host file
bin/setup myhost.com
successfully installed magento database also created success fully but I can not access through browser.
When loading docker-compose up, wordpress loads on the url but the mysqli_connect function is undefined because of the absence of the extension.
I have tried to add the following under the fpm image
command: "docker-php-ext-install mysqli"
I have tried to add a Dockerfile into the directory of the docker-compose.yml file containing
version: "3"
services:
#database
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- wpsite
# webserver
nginx:
image: nginx:latest
ports:
- "8080:80"
links:
- fpm
volumes:
- /Users/connergesbocker/Github/cbgesbocker/dotfiles/root/etc/nginx/conf.d/village.conf:/etc/nginx/conf.d/village.conf
- /Users/connergesbocker/WordPress:/WordPress
networks:
- wpsite
# phpmyadmin
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8888:8888"
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: wordpress
networks:
- wpsite
fpm:
image: php:5.6.20-fpm
ports:
- "90:9000"
# command: "docker-php-ext-install mysqli"
links:
- db
volumes:
- /Users/connergesbocker/WordPress:/WordPress
working_dir: "/"
networks:
- wpsite
networks:
wpsite:
volumes:
db_data:```
You could customize your dockerfile & add install in it:
Dockerfile:
FROM php:5.6.20-fpm
RUN docker-php-ext-install mysqli
Part of docker-compose.yaml:
fpm:
build: .
image: myphp:1
ports:
- "90:9000"
# command: "docker-php-ext-install mysqli"
links:
- db
volumes:
- /Users/connergesbocker/WordPress:/WordPress
working_dir: "/"
networks:
- wpsite
your override will install the extension but the container will stop after installation because php-fpm will not start by overriding CMD. Replace the command with below one.
command:
- /bin/sh
- -c
- |
docker-php-ext-install mysqli
echo "extension installed.....starting php-fpm........................................"
php-fpm
I set up 2 projects (Admin and API) and try to move into docker on local.
I can access the running web instances on both without any problems, but when the Admin tries to make a Curl requests to the API, I get a cURL error:
cURL error 7: Failed to connect to localhost port 8080
This is my docker-compose.yml file contents:
version: "3.1"
services:
memcached:
image: memcached:alpine
container_name: project-admin-memcached
redis:
image: redis:alpine
container_name: project-admin-redis
mariadb:
image: mariadb:10.1
container_name: project-admin-mariadb
working_dir: /application
volumes:
- ./Projects:/application
environment:
- MYSQL_ROOT_PASSWORD=docker
- MYSQL_DATABASE=db_test
- MYSQL_USER=test
- MYSQL_PASSWORD=test
ports:
- "8083:3306"
# docker-compose exec webserver sh
# docker exec -it project-admin-webserver nginx -s reload
webserver:
image: nginx:alpine
container_name: project-admin-webserver
working_dir: /application
volumes:
- ./Projects/Api:/application/api
- ./Projects/Admin:/application/admin
- ./Docker/nginx:/etc/nginx/conf.d
ports:
- "8080:8080"
- "8090:8090"
# docker-compose exec php-fpm bash
php-fpm:
build: Docker/php-fpm
container_name: project-admin-php-fpm
working_dir: /application
volumes:
- ./Projects:/application
- ./Docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
I can access both projects from my browser with:
http://localhost:8080/ <= API
http://localhost:8090/ <= Admin
How can I fix this?
inside your docker network (create by default with a compose), you have to use the container name.
So inside a container you have to use http://webserver:8080