Docker, php and python - php

I have a problem to getting php to call a python script. I donĀ“t know how I should get php to have access to python via exec.
Her is my yml file:
nginx:
build: ./nginx/
ports:
- 80:80
links:
- php
volumes_from:
- app
php:
build: ./php/
expose:
- 9000
links:
- mysql
volumes_from:
- app
app:
image: php:7.0.11-fpm
volumes:
- ./src:/var/www/html
command: "true"
mysql:
image: mysql:latest
volumes_from:
- data
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: project
MYSQL_USER: project
MYSQL_PASSWORD: project
data:
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
phpmyadmin:
image: phpmyadmin/phpmyadmin
ports:
- 8888:80
links:
- mysql
environment:
PMA_HOST: mysql
Should I add a python container also? Or whats best here?

Related

What is wrong with my Laravel docker compose File?

Can anybody help me with the following? I have a docker-compose file with the following services PHP, Mysql, Redis, and Nginx. The docker-compose file builds without any issues but when I try the URL its not working. The file is down below
version: '3.8'
services:
php:
build: ./docker-compose/php-81/build
image: php-81
container_name: cumax-php-db
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
- ./docker-files/storage/logs/php:/var/www/default/logs
networks:
- onboarding
db:
image: mysql:8.0
container_name: cumax-mysql-db
restart: unless-stopped
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql8.0/storage:/var/lib/mysql
networks:
- onboarding
nginx:
image: nginx:1.17-alpine
container_name: cumax-nginx
restart: unless-stopped
ports:
- "8070:80"
volumes:
- ./:/var/www
- ./docker-compose/nginx/conf.d:/etc/nginx/conf.d
networks:
- onboarding
redis:
image: "redis:alpine"
ports:
- "6379:6379"
networks:
- onboarding
networks:
onboarding:
On php you don't publish the port.
On the Nginx you only publish to port 8070 on the host.
What is the URL you are using? It should be http://< host >:8070/
And then the nginx should proxy onwards to php.

Communication between a docker application and another one on the local system [duplicate]

This question already has answers here:
From inside of a Docker container, how do I connect to the localhost of the machine?
(40 answers)
Closed 5 months ago.
How can a Docker container communicate with a local application that is not in Docker?
I have a Symfony container (PHP) and I want to communicate with a nodejs application for socket (so I need input and output for the 1337 port).
How can I make a communication between these applications?
My docker-file:
version: "3.7"
volumes:
db-data:
networks:
dev:
driver: bridge
services:
mariadb:
container_name: symfony_mariadb
image: mariadb:10.9.3-jammy
restart: always
environment:
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_ROOT_PASSWORD: root
volumes:
- db-data:/var/lib/mysql
expose:
- 3306
ports:
- "3306:3306"
phpmyadmin:
container_name: phpmyadmin
depends_on:
- mariadb
restart: always
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mariadb
PMA_USER: root
PMA_PASSWORD: root
ports:
- "${PHPMYADMIN_PORT:-8081}:80"
redis:
container_name: redis
image: redis:7.0.5-alpine3.16
ports:
- "6379:6379"
volumes:
- ./data/redis:/data/redis
nginx:
build:
context: .docker/nginx
restart: on-failure
volumes:
- ./:/var/www/server:cached
- ./.docker/nginx/server.conf:/etc/nginx/conf.d/server.conf:cached
ports:
- "${NGINX_PORT:-8000}:80"
depends_on:
- php
- mariadb
- redis
php:
build:
context: .docker/php
restart: on-failure
ports:
- 5000:8000
volumes:
- ./:/var/www/server:cached
- ./:/var/www/symfony
- ./logs/symfony:/var/www/symfony/app/logs
- ./.docker/php/php.ini:/usr/local/etc/php/php.ini:ro
depends_on:
- mariadb
- redis
user: "${ID_USER:-1001}:${ID_USER:-1001}"
Normally yo can see host machine port from docker, you try using host IP ?
Note: if this host IP is in a different network segment of internals IPs form dockers, like 192.168.1.28

Use `WP_CLI::add_command` with WordPress in Docker

I'm using WordPress in Docker with the following configuration:
# /wp-dock/docker-compose.yml
---
version: "3.3"
services:
db:
container_name: ${APP_NAME}-wordpress-db
image: "mysql:5.7"
platform: linux/amd64
volumes:
- "./data/mysql:/var/lib/mysql"
restart: always
ports:
- 18766:3306
environment:
- MYSQL_DATABASE=${DB_NAME}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8080:80"
environment:
- PMA_HOST=db
wordpress:
container_name: ${APP_NAME}-wordpress
depends_on:
- db
image: "wordpress:latest"
ports:
- "81:80"
environment:
WORDPRESS_DB_HOST: "db:3306"
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
volumes:
- "./wordpress:/var/www/html"
- "./plugins:/var/www/html/wp-content/plugins"
- "./themes:/var/www/html/wp-content/themes"
wpcli:
container_name: ${APP_NAME}-cli
depends_on:
- wordpress
image: wordpress:cli-php8.1
user: 1000:1000
command: tail -f /dev/null
volumes:
- "./wordpress:/var/www/html"
environment:
WORDPRESS_DB_HOST: "db:3306"
WORDPRESS_DB_NAME: ${DB_NAME}
WORDPRESS_DB_USER: ${DB_USER}
WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
I can access and use wp-cli like so:
docker exec site-cli wp --info
This works well. But I'm writing a plugin in the WordPress container that extends the wp-cli with a custom command as seen here.
When I try run that command, wp-cli says that it's not a registered command.
Any ideas on how to extend wp-cli in a Docker container?

Is it possible to use the same docker container for multiple websites

until a new version of php or mysql comes out I generally always use the same setup, so at the moment I create 3 containers for every site I create:-
Site 1:-
version: '3.1'
services:
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: site1
ports:
- 8000:80
restart: always
volumes:
- .:/var/www/html
networks:
- site1
mysql:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: site1
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
networks:
- larastock
phpmyadmin:
depends_on:
- site1
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: password
networks:
- site1
networks:
site1:
volumes:
db_data:
Site 2:-
version: '3.1'
services:
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: site2
ports:
- 8000:80
restart: always
volumes:
- .:/var/www/html
networks:
- site2
mysql:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: site1
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
networks:
- larastock
phpmyadmin:
depends_on:
- site2
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: password
networks:
- site2
networks:
site2:
volumes:
db_data:
They are identical except for the network but this means I have 6 containers when really I only need 3. Is it possible to tell site 2 to use the services that site 1 created or does this go against the whole point of docker?
So what I would like is to change:-
Site 1 uses php, mysql and phpmyadmin. Site 2 uses php1, mysql1, phpmyadmin1.
to:
both site 1 and site 2 using the same container's but having their own database:-
Site 1 uses php, mysql (database site1) and phpmyadmin. Site 2 uses php, mysql (database site2) and phpmyadmin

Problems PHP MARIADB PHPMYADMIN using docker-compose

I've been this last two weeks searching how to link my phpmyadmin and my database, to create a PHP development workspace, through docker-compose but I am not able to connect to the database through the phpmyadmin port.
version: '3'
services:
servicio_php:
image: php:7.3-rc-apache
volumes:
- ./web/:/var/www/html
expose:
- "80"
ports:
- "80:80"
links:
- db
db:
image: mariadb:latest
restart: always
volumes:
- ./Volumenes/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root123
MYSQL_USER: user
MYSQL_PASSWORD: user123
MYSQL_DATABASE: bbdd1
expose:
- "3306"
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
container_name: phpmyadmin
environment:
PMA_ARBITRARY: 1
MYSQL_ROOT_PASSWORD: root123
MYSQL_USERNAME: user
PMA_HOST: db
MYSQL_PASSWORD: user123
restart: always
ports:
- "8080:80"
volumes:
- ./sessions:/sessions/
depends_on:
- db
links:
- db
I am using windows 10 version of dockers 18.06.1-ce and also when i run docker-compose up i see there are some probles with Innodb but ive read is not a problem.
I am not able to see whats wrong and probably I am not the only one with this problem.

Categories