Docker mySql:5.7 not running - php

I am a beginner with Docker. I followed a tutorial and add docker-compose.yml file.
The file looks like this -
version: '2'
services:
webserver:
build: ./docker/webserver
image: image_name
ports:
- "80:80"
- "443:443"
volumes:
- /Users/user_name/Sites/project_name:/var/www/html
links:
- db
db:
image: mysql:5.7
ports:
- "3306:3306"
volumes:
- ./db:/usr/local/mysql/bin/mysql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=DB_NAME
I am able to run the project on the web on localhost address but the connection to mysql is not ok.
When I run 'docker ps -a' on terminal ( I am using Mac)the Status of the mysql is - Exited (1) 16 seconds ago and the PORTS is empty.
Any idea/help?

Related

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

MacOs - localhost file not found 404

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?

After installing/configuration of magento with docker getting unable to connect

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.

Docker on Windows: how to run multiple websites (LAMP stack)?

I am trying to set up a local environment for web development (LAMP stack) using Docker.
All websites live in folder called Sites with this structure:
/Sites
-- site1.local
-- www
-- site2.local
-- www
For every website I need its own version of PHP and MySQL.
So far I was able to run one local website with this docker-compose.yml (uses php:7.1-apache):
version: "3"
services:
webserver:
build:
context: ./bin/webserver
container_name: 'sp-webserver'
restart: 'always'
ports:
- "80:80"
- "443:443"
links:
- mysql
volumes:
- ${DOCUMENT_ROOT-./www}:/var/www/html
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
mysql:
build: ./bin/mysql
container_name: 'sp-mysql'
restart: 'always'
ports:
- "3306:3306"
volumes:
- ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
- ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: sp-demo
MYSQL_USER: sp-demo
MYSQL_PASSWORD: sp-demo
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'rb-phpmyadmin'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- '8080:80'
volumes:
- /sessions
redis:
container_name: 'rb-redis'
image: redis:latest
ports:
- "6379:6379"
The website is available at http://localhost:80
Questions:
1) How do I make it accesible by domain domain, for example, http://site1.local instead of http://localhost:80? I heard I need some Nginx Proxy for this (https://github.com/jwilder/nginx-proxy), but I can't understand how to set it up with Apache in my case.
2) How to set up the second website (http://site2.local) the same way to run it simultaneously? As far as I understand, I would need to change all ports (80, 443 and 3306), otherwise I will have a conflict when I run docker-compose up -d? Is it possible without changing ports?
Thanks for the answers!

Php is unable to write file in docker

I am runing a Symfony 3.4 application with docker, i need to upload a file and save it to /web/files. When i'm trying to do so i get an error:
Unable to create the "/home/docker/web/files/" directory
Note that i mounted the directory as Read-Write in cocker compose:
version: '2'
services:
front:
image: nginx
ports:
- "81:80"
links:
- "engine:engine"
- "db:db"
volumes:
- ".:/home/docker:ro"
- "./docker/front/default.conf:/etc/nginx/conf.d/default.conf:ro"
engine:
build: ./docker/engine/
volumes:
- ".:/home/docker:rw"
- "./docker/engine/php.ini:/usr/local/etc/php/conf.d/custom.ini:ro"
links:
- "db:db"
working_dir: "/home/docker"
db:
image: camptocamp/postgres:9.6
ports:
- "5433:5432"
environment:
- "POSTGRES_DB=pfe"
- "POSTGRES_PASSWORD=admin"
- "POSTGRES_USER=admin"
- "PGDATA=/var/lib/postgresql/data/pgdata"
I even created the directory files in /web, but its not working!
I create a separate container for my files, and just base it on an apache image. Then I use the volumes_from key to pass it into my php. Give something like this a try:
services:
apache:
build: ./build/httpd
links:
- php
ports:
- 80:80
- 443:443
volumes_from:
- app
php:
build: ./build/php
ports:
- 9000
- 9001
volumes_from:
- app
links:
- mariadb
- mail
app:
image: httpd:latest
volumes:
- ./:/var/www/html
command: "echo true"

Categories