Can someone please help.
I was running successfully my Symfony project via Docker containers. Suddenly when I access http://localhost/ I get the File not found. error?
I now that it means that system can not locate my files, but I am not sure what happened.
I see that my containers are built and running okay.
Also the same message I get when I try to test app endpoints through Postman.
I am on Mac Monterey 12.4.
Everything was working fine couple of hours ago. I just switched branches to change something, then switched back. The problem was on both branches..
Can someone help, I do not know what to do?
Docker config:
services:
db:
image: postgres:${POSTGRES_VERSION:-12}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-name}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-pass}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
volumes:
- $PWD/postgres-data:/var/lib/postgresql/data:rw
profiles:
- db-in-docker
ports:
- "5432:5432"
networks:
- symfony
redis:
image: "redis:alpine"
command: redis-server /usr/local/etc/redis/redis.conf
ports:
- "6379:6379"
volumes:
- $PWD/redis-data:/var/lib/redis
- $PWD/redis/redis.conf:/usr/local/etc/redis/redis.conf
environment:
- REDIS_REPLICATION_MODE=master
networks:
- symfony
php:
container_name: "backend_php"
build:
context: ..
dockerfile: docker/php/Dockerfile
target: dev
args:
TIMEZONE: ${TIMEZONE}
volumes:
- symfony_docker_app_sync:/var/www/symfony/
depends_on:
- redis
networks:
- symfony
nginx:
build:
context: ./nginx
volumes:
- ../:/var/www/symfony/
ports:
- 80:80
depends_on:
- php
networks:
- symfony
env_file:
- .env.nginx.local
First of all: Why do you donĀ“t use the built in symfony server for local development? However - how looks your docker container configuration for your webserver?
Related
I'm quite bad at creating docker-compose and I currently have a problem when I try to build a new project.
After the build I can't access my mariadb server within my php app container, I've got this error:
PDO::__construct(): php_network_getaddresses: getaddrinfo for mariadb
failed: Name does not resolve
So I know something is misconfigured but I don't know what, yet. I tried many changes but nothing that worked.
Here is my current docker-compose.yml:
version: "3.8"
networks:
# used by some services (php) to communicate with other docker-compose.yaml
censored.com:
external:
name: censored.com
services:
app:
build:
context: .
target: symfony_php
args:
- secret=id=composerauth,src=${HOME}/.composer/auth.json
restart: unless-stopped
healthcheck:
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
environment:
APP_ENV: dev
HOST: www.censored.lan
networks:
- default
- censored.com
volumes:
- ./:/srv/app:rw,cached
- ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini
- ${HOME}/.composer/auth.json:/root/.composer/auth.json
# If you develop on Linux, comment out the following volumes to just use bind-mounted project directory from host
- ./var/cache:/srv/app/cache:rw
- ./var/log:/srv/app/logs:rw
depends_on:
- mariadb
extra_hosts:
- www.censored.lan:127.0.0.1
nginx:
build:
context: .
target: symfony_nginx
args:
- secret=id=composerauth,src=${HOME}/.composer/auth.json
restart: unless-stopped
depends_on:
- app
environment:
NGINX_DOMAIN: www.censored.lan
ports:
- 8001:80
volumes:
- ./docker/nginx/templates/dev.conf.template:/etc/nginx/templates/default.conf.template:ro
- ./docker/nginx/rules/rules.dev.conf:/etc/nginx/rules.conf:ro
- ./public:/srv/app/public:ro
- ./src:/srv/app/src:ro
mariadb:
image: mariadb:10.7
environment:
MYSQL_ROOT_PASSWORD: changeme
MYSQL_DATABASE: database
MYSQL_USER: user
MYSQL_PASSWORD: changeme
networks:
- default
- censored.com
ports:
- '3307:3306'
restart: on-failure
volumes:
- db_data:/var/lib/mysql
volumes:
db_data: {}
Can someone help me to fix the issue please?
Thanks !
The problem wasn't related to my docker-compose configuration file.
My app is a PHP Symfony app and it was doing a "cache:clear" after the initial "composer install" during the build. The "cache:clear" was triggering calls to the database which wasn't ready yet.
To solve this I just had to set my mariadb version to my "DATABASE_URL" parameter in my Symfony app, to avoid useless database queries.
I am dockerizing an app that has several different services and I have used Docker Compose file to achieve this Single docker-compose.yml file for all the services and one Dockerfile for each service.
Frontend(angular)[http://localhost:4200]
Backend(PHP)[http://localhost:80]
Backend Database(Mysql)
Authentication Layer(NodeJS)[http://localhost:4454]
Authentication Layer Database(Mysql)
So far I have successfully containerized all these services but there is one problem when the application tries to log in the "Auth Layer(NodeJS)" sends a request on the "Backend(PHP)" API for some data processing on this step I get "ECONNREFUSED 127.0.0.1:80" error but if I try the same API on Postman it works but not from "Auth Layer(NodeJS)" I have also tried to call some third party API and it also works fine in AuthLayer so what should be the issue as I am new to Docker I am unable to find a solution in days.
this is my docker.compose.yml file
services:
angular-service:
container_name: wms_frontend
build: ../frontend/.
ports:
- "4200:80"
php:
build:
context: .
image: wms-backend
networks:
- frontend
- backend
environment:
- MYSQL_HOST=wms-backend-mysql-app
- MYSQL_USER=wmsroot
- MYSQL_PASSWORD=pass
- MYSQL_DB=dbname
volumes:
- ./:/var/www/html/wms/backend
ports:
- "80:80"
container_name: wms-backend-php-app
mysql:
image: mysql:5.7
networks:
- backend
environment:
- MYSQL_ROOT_PASSWORD=rootpassword
- MYSQL_USER=wmsroot
- MYSQL_PASSWORD=pass
- MYSQL_DATABASE=dbname2
container_name: wms-backend-mysql-app
phpmyadmin:
image: phpmyadmin/phpmyadmin:4.7
depends_on:
- mysql
networks:
- backend
ports:
- "40002:40002"
environment:
- PMA_HOST=wms-backend-mysql-app
- PMA_PORT= 3306
volumes:
- /sessions
container_name: wms-backend-phpmyadmin-app
app:
container_name: auth_layer
restart: always
build: ../../auth_layer/.
networks:
- backend
volumes:
- ../../auth_layer/./:/usr/src/app
- /usr/src/app/node_modules
ports:
- "4454:4454"
links:
- db
depends_on:
db:
condition: service_healthy
db:
image: mariadb
restart: always
ports:
- "3308:3306"
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD= YES
- MYSQL_DATABASE=auth_layer
- MYSQL_USER= root
- MYSQL_PASSWORD=
volumes:
- ../../auth_layer/dump/:/docker-entrypoint-initdb.d
networks:
- backend
healthcheck:
test: ["CMD", "mysql", "-h", "db","-u","root", "mysql", "-e", "select 1"]
interval: 1s
retries: 20
networks:
local:
driver: bridge
networks:
frontend:
backend:
When your app is running inside a docker container, localhost points no longer to your development laptop (or server) it points to the container itself.
As each application is running in separeted container when the front access to the back, you cannot use localhost. As localhost points to the front container, and the back is not deployed there.
You should use the container name instead localhost when specificying the connection urls.
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.
The php Docker container no longer reacts after PHP exception. I can correct the error or do something else, it remains the exception. I get no error in the console.
The only thing that helps, is to restart the PHP container.
Does anyone have an idea or similar problem?
I use Docker on Mac with PhpStorm.
version: '2'
services:
php:
container_name: php2
image: tamuarchi/yii2-mssql:latest
volumes:
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ./:/app:delegated
ports:
- '80:80'
networks:
mynetwork:
aliases:
- web2
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal xdebug.idekey="PHPSTORM"
memcached:
container_name: memcached2
image: memcached:latest
ports:
- "0.0.0.0:11211:11211"
networks:
mynetwork:
driver: bridge
At the moment I'm building my own dev environment because I want to get rid of MAMP.
I created a docker-compose file with a nginx proxy and it's basically working. My problem is, that several old php projects require different php versions.
Here is how far I already got with my compose file:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
project1:
build: ./config/5.3.29/nginx/
container_name: project1
volumes:
- ./project1/:/var/www/html
links:
- php-5.3.29:php
environment:
- "VIRTUAL_HOST=project1.org"
expose:
- "8080"
project2:
build: ./config/5.6/nginx/
container_name: project2
volumes:
- ./project2/:/var/www/html
links:
- php-5.6:php
environment:
- "VIRTUAL_HOST=project2.de"
expose:
- "8081"
php-5.3.29:
build: ./config/5.3.29/php/
container_name: php-5.3.29
ports:
- 9000:9000
php-5.6:
build: ./config/5.6/php/
container_name: php-5.6
ports:
- 9001:9000
As you can see, I have two projects. The PHP containers require to volume from the the same path as the project does. Is there a way to generate the path dynamically? Project 3 will also use php 5.6.
Or am I using the wrong way to go in general? In the end there will be around 10 Magento online shops.
Thank you for your help!
Thank you for your answer!
Today I was able to solve my problem with this docker-compose file:
version: '2'
services:
nginx:
build: ./config/nginx/
container_name: nginx
volumes_from:
- www_data
links:
- php-5.3.29
- php-5.5
ports:
- 80:80
php-5.3.29:
build: ./config/5.3.29/
container_name: php-5.3.29
volumes_from:
- www_data
php-5.5:
build: ./config/5.5/
container_name: php-5.5
volumes_from:
- www_data
php-5.6:
build: ./config/5.6/
container_name: php-5.6
volumes_from:
- www_data
www_data:
image: tianon/true
volumes:
- .:/var/www/html
I removed the proxy and used the nginx config to handle the different websites. Then I was able to include the different php versions like this:
fastcgi_pass php-5.5:9000;
You can reference directories above the compose file like ../sites:/var/www/html or similar. Not sure when you say "dynamically" if you need additional logic to generate the paths.
In general it seems like your naming is a bit too specific, which might be fine for an initial workstation, but as things start to change, it's going to be harder to maintain.