Docker-Compose phpmyadmin and mysql together for local development - mysql

version: "3.1"
services:
redis:
image: redis:alpine
container_name: larablog-redis
the code was working fine until I added the following services
db:
image: mysql:8.0
container_name: larablog-mysql
working_dir: /application
volumes:
- ./src:/application
environment:
- MYSQL_ROOT_PASSWORD=rootpass
- MYSQL_DATABASE=larablog
- MYSQL_USER=larauser
- MYSQL_PASSWORD=larauserpass
ports:
- "8890:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_ARBITRARY: 1
MYSQL_USER: larauser
MYSQL_PASSWORD: larauserpass
MYSQL_ROOT_PASSWORD: rootpass
ports:
- "80:80"
links:
# for mysql container
- "db:db"
volumes:
db:
driver: "local"
I am trying to follow a method I found on https://gotechnies.com/docker-compose-yml-mysql-phpmyadmin/ however I cannot start from scratch because I need the laravel framework as well
webserver:
image: nginx:alpine
container_name: larablog-webserver
working_dir: /application
volumes:
- ./src:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8888:80"
php-fpm:
build: phpdocker/php-fpm
container_name: larablog-php-fpm
working_dir: /application
volumes:
- ./src:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
I get this error when i try to run docker-compose up -d ...
ERROR: yaml.parser.ParserError: while parsing a block mapping
in ".\..\docker-compose.yml", line 27, column 6
expected <block end>, but found '<block mapping start>'
in ".\..\docker-compose.yml", line 35, column 9
How can I overcome this error?

Related

Node.js service is unable to connect with Mysql using docker composer

I am trying to run 2 Node.js and 2 mysql services with docker composer, both of Node.js services are unable to connect with Mysql services while I was able to login into both Mysql containers with respective credentials.
Node.js service giving the following error:
original: Error: connect ECONNREFUSED 172.22.0.2:3308
enter image description here
I have also successfully connected a PHP script with both of the MySQL services.
My docker-composer file :
version: '3.8'
services:
genreapp:
depends_on:
- genresqldb
build: ./genre
#command: sh -c './wait-for-it.sh -t 0 genresqldb:$DB_PORT_GENRE'
restart: unless-stopped
env_file: ./.env
links:
- genresqldb
volumes:
- ./:/app
ports:
- $NODE_PORT_GENRE:$NODE_PORT_GENRE
environment:
- DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD_GENRE
- DB_NAME=$DB_NAME_GENRE
- DB_PORT=$DB_PORT_GENRE
- DIALTEC=$DIALTEC
- APP_PORT=$NODE_PORT_GENRE
- HOST=$HOST
- DB_HOST_GENRE=genresqldb
stdin_open: true
tty: true
movieapp:
depends_on:
- moviesqldb
build: ./movie
restart: unless-stopped
env_file: ./.env
links:
- moviesqldb
volumes:
- ./:/app
#command: sh -c './wait-for-it.sh -t 0 moviesqldb:$DB_PORT_MOVIE'
ports:
- $NODE_PORT_MOVIE:$NODE_PORT_MOVIE
environment:
- DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD_MOVIE
- DB_NAME=$DB_NAME_MOVIE
- DB_PORT=$DB_PORT_MOVIE
- DIALTEC=$DIALTEC
- APP_PORT=$NODE_PORT_MOVIE
- HOST=$HOST
- DB_HOST_GENRE=moviesqldb
stdin_open: true
tty: true
genresqldb:
image: mysql:5
# restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD_GENRE
- MYSQL_DATABASE=$DB_NAME_GENRE
expose:
- $DB_PORT_GENRE
ports:
- $DB_PORT_GENRE:$DB_PORT
volumes:
- db:/var/lib/mysqli
moviesqldb:
image: mysql:5
# restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD_MOVIE
- MYSQL_DATABASE=$DB_NAME_MOVIE
expose:
- $DB_PORT_MOVIE
ports:
- $DB_PORT_MOVIE:$DB_PORT
volumes:
- db:/var/lib/mysqli
volumes:
db:
Just by using Version 3 resolve the issue.

mysql database name and credentials inside docker container not updating

I have a LAMP stack with laravel setup in docker-compose containers,everything seems to be working fine so far. I initially had a test database with the name of homestead setup in docker-compose.yml that was just there for testing now i want to change it to something more meaningful like my project name. let me show you my docker-compose.yml
version: '3'
networks:
laravel:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: nginx
ports:
- 80:80
volumes:
- ./src:/var/www/html:delegated
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- 3306:3306
environment:
MYSQL_DATABASE: alis
MYSQL_USER: alis
MYSQL_PASSWORD: pass
MYSQL_ROOT_PASSWORD: pass
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
volumes:
- ./mysql:/var/lib/mysql
php:
build:
context: .
dockerfile: php.dockerfile
container_name: php
volumes:
- ./src:/var/www/html:delegated
networks:
- laravel
composer:
build:
context: .
dockerfile: composer.dockerfile
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
user: laravel
entrypoint: ['composer', '--ignore-platform-reqs']
networks:
- laravel
npm:
image: node:latest
container_name: npm
volumes:
- ./src:/var/www/html
ports:
- 3000:3000
- 3001:3001
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html:delegated
depends_on:
- mysql
working_dir: /var/www/html
user: laravel
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
restart: always
container_name: phpmyadmin
depends_on:
- mysql
ports:
- "8081:80"
environment:
PMA_HOST: mysql
MYSQL_ROOT_PASSWORD: secret
networks:
- laravel
the problem is phpmyadmin is still using the old database and credentials , it tried the following solutions
docker-compose down
docker-compose down -v
then
docker-compose up -d
this didnt work.Out of frustration even thought this is probably not the best way to do it, I removed all containers, all images and then ran
docker-compose up -d
to re-install everything from scratch to my surprise phpmyadmin still picks up the old database config.Does anyone know the reason for this behaviour?
Your phpmyadmin service tries to connect as root:secret (MYSQL_ROOT_PASSWORD) while your mysql service defines root:pass (MYSQL_ROOT_PASSWORD) as admin user.
See the available configuration here:
https://hub.docker.com/_/phpmyadmin
https://hub.docker.com/_/mysql

How can I add phpMyAdmin in docker-compose

Hello everyone I have this docker-compose file
version: '3'
networks:
laravel:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html:delegated
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: gestionParking
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: php.dockerfile
container_name: php
volumes:
- ./src:/var/www/html:delegated
ports:
- "9000:9000"
networks:
- laravel
composer:
build:
context: .
dockerfile: composer.dockerfile
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
user: laravel
networks:
- laravel
entrypoint: ['composer', '--ignore-platform-reqs']
npm:
image: node:13.7
container_name: npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html:delegated
depends_on:
- mysql
working_dir: /var/www/html
user: laravel
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
And I want to add phpMyAdmin to have graphical interface of my database, I try this but it doesn't work.
...
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: gestionParking
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_ROOT_PASSWORD: root
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
MYSQL_ROOT_PASSWORD: secret
PMA_HOST: mysql
PMA_PORT: 3306
restart: always
ports:
- "8081:80"
networks:
- laravel
I think it's possible, but I think I'm going about it wrong.
I know we need to make a connection between mysql service and phpmyadmin but I don't know how to do it.
Can I help me please
version: '3'
services:
nginx:
container_name: nginx
image: nginx:1.17
restart: always
ports:
- "9998:80"
volumes:
- ../:/var/www
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
container_name: php
build:
context: .
dockerfile: Dockerfile
restart: always
volumes:
- ../:/var/www
- ~:/home
- ./php-config/php.ini:/usr/local/etc/php/php.ini
app:
build:
context: .
dockerfile: Dockerfile
image: hakase-labs/laravel
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www/html
volumes:
- ./:/var/www/html
networks:
- mynet
composer:
container_name: composer
image: composer:1.9.0
command: tail -f /dev/null
volumes:
- ../:/var/www
mysql:
container_name: mysql
image: mysql:5.7
command: mysqld --max-allowed-packet=64M --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
volumes:
# Mount mysl data directory to keep it perisstent on host system.
# Use this only in development environment
# Mysql cannot write to data folder as it is owned by user on host.
# So chown 999:999 data folder when it is first created
# Todo: For some reason we are not able to mount log directory from host to mysql container. We need to fix this in future so that we can better manage mysql logs from host machine - Harsha
#- ~/storage/mysql/log:/var/log/mysql
- ~/storage/mysql/data:/var/lib/mysql
environment:
- "MYSQL_ROOT_PASSWORD=pasword"
- "MYSQL_DATABASE=name"
- "MYSQL_USER=name"
- "MYSQL_PASSWORD=password"
ports:
- "3306:3306"
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin/phpmyadmin
restart: always
environment:
- PMA_HOST=mysql
- PMA_PORT=3306
ports:
- 8001:80
volumes:
- /sessions

Docker - PHP/MySQL - php_network_getaddresses: getaddrinfo failed: Name or service not known

I have the following docker-compose.yml, mostly copied from some tutorial (https://medium.com/#romaricp/the-perfect-kit-starter-for-a-symfony-4-project-with-docker-and-php-7-2-fda447b6bca1):
version: '3'
services:
apache:
build: .docker/apache
container_name: sf4_apache
ports:
- 80:80
- 443:443
volumes:
- .docker/config/vhosts:/etc/apache2/sites-enabled
- .:/home/wwwroot/sf4:cached
depends_on:
- php
mysql:
image: mysql:5.7
container_name: sf4_mysql
command: "--default-authentication-plugin=mysql_native_password"
restart: always
ports:
- 3306:3306
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sf4
MYSQL_USER: sf4
MYSQL_PASSWORD: sf4
php:
build: .docker/php
container_name: sf4_php
volumes:
- .:/home/wwwroot/sf4
environment:
- maildev_host=sf4_maildev
depends_on:
- maildev
- mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: sf4_phpmyadmin
environment:
PMA_HOST: sf4_mysql
PMA_PORT: 3306
ports:
- 8080:80
links:
- mysql
maildev:
image: djfarrelly/maildev
container_name: sf4_maildev
ports:
- 8001:80
Now my problem is, that I cannot manage to connect to MySQL. Wheter from PHP nor PhpMyAdmin. I've tried the following connection strings, but none of them work:
DATABASE_URL=mysql://root:root#mysql:3306/sf4
DATABASE_URL=mysql://sf4:sf4#mysql:3306/sf4
DATABASE_URL=mysql://root:root#sf4_mysql:3306/sf4
DATABASE_URL=mysql://sf4:sf4#sf4_mysql:3306/sf4
... and hundreds more
But I always get:
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known
Or
SQLSTATE[HY000] [2002] No route to host
Or
SQLSTATE[HY000] [2002] Connection refused
Thanks to #emix and #LinPy, who helped me out in the comments, here is the fixed configuration:
version: '3'
services:
apache:
build: .docker/apache
container_name: sf4_apache
ports:
- 80:80
- 443:443
volumes:
- .docker/config/vhosts:/etc/apache2/sites-enabled
- .:/home/wwwroot/sf4:cached
depends_on:
- php
mysql:
image: mysql:5.7
container_name: sf4_mysql
#command: "--default-authentication-plugin=mysql_native_password"
#restart: always
ports:
- 3306:3306
volumes:
- .docker/data/db:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: sf4
MYSQL_USER: sf4
MYSQL_PASSWORD: sf4
php:
build: .docker/php
container_name: sf4_php
volumes:
- .:/home/wwwroot/sf4
environment:
- maildev_host=sf4_maildev
depends_on:
- maildev
- mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: sf4_phpmyadmin
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- 8080:80
links:
- mysql
maildev:
image: djfarrelly/maildev
container_name: sf4_maildev
ports:
- 8001:80
Connection string:
DATABASE_URL=mysql://sf4:sf4#mysql/sf4

docker phpmyadmin Cannot log in to the MySQL server

I get error in http://localhost:8080/index.php
user bralion pass 123
Cannot log in to the MySQL server
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Try again
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Try again
here is my docker_compose.yml
version: "3.1"
services:
webserver:
image: nginx:alpine
container_name: bralion-webserver
working_dir: /application
networks:
itbcode_net:
ipv4_address: 10.3.0.11
volumes:
- .:/application
- ./itbcode_docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8089:80"
mysql:
image: mysql:5.7
container_name: bralion-mysql
working_dir: /application
networks:
itbcode_net:
ipv4_address: 10.3.0.12
volumes:
- .:/application
- ./var/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=bralion
- MYSQL_USER=bralion
- MYSQL_PASSWORD=123
- MYSQL_ALLOW_EMPTY_PASSWORD=true
ports:
- "8088:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- '8080:80'
php-fpm:
build: itbcode_docker/php-fpm
container_name: bralion-php-fpm
working_dir: /application
networks:
itbcode_net:
ipv4_address: 10.3.0.13
volumes:
- .:/application
- ~/.ssh/:/root/.ssh/
- ~/.bash_history:/root/.bash_history
- ./itbcode_docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
redis:
image: redis:alpine
container_name: sd-redis
UPDATE 1
i Update config (add ~/.composer and add phpmyadmin to itb_network)
version: "3.1"
services:
webserver:
image: nginx:alpine
container_name: bralion-webserver
working_dir: /application
networks:
itbcode_net:
ipv4_address: 10.3.0.11
volumes:
- .:/application
- ./itbcode_docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8089:80"
mysql:
image: mysql:5.7
container_name: bralion-mysql
working_dir: /application
networks:
itbcode_net:
ipv4_address: 10.3.0.12
volumes:
- .:/application
- ./var/mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=bralion
- MYSQL_USER=bralion
- MYSQL_PASSWORD=123
- MYSQL_ALLOW_EMPTY_PASSWORD=true
ports:
- "8088:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
networks:
itbcode_net:
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- '8080:80'
php-fpm:
build: itbcode_docker/php-fpm
container_name: bralion-php-fpm
working_dir: /application
networks:
itbcode_net:
ipv4_address: 10.3.0.13
volumes:
- .:/application
- ~/.ssh/:/root/.ssh/
- ~/.composer/:/root/.composer/
- ~/.bash_history:/root/.bash_history
- ./itbcode_docker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
redis:
image: redis:alpine
container_name: sd-redis
networks:
itbcode_net:
elastic-search:
image: willdurand/elk
networks:
itbcode_net:
container_name: bralion-elastic
ports:
- 81:80
volumes:
- ./elk/logstash:/etc/logstash
- ./elk/logstash/patterns:/opt/logstash/patterns
# node:
# build:
# context: ./itbcode_docker/node
# working_dir: /srv
# volumes:
# - ./:/srv/
networks:
itbcode_net:
driver: bridge
ipam:
config:
- subnet: 10.3.0.0/16
The problem is that the two containers are in different networks. The phpmyadmin container is only in the default network (because you didn't specify another network for it), the mysql container is only in the itbcode_net network (once you specify another network, the container will be removed from the default network unless you also add - default). You need to either add phpmyadmin to itbcode_net or add mysql to default, otherwise they can't communicate with each other.
webserver, mysql, and php-fpm are on the network itbcode_net.
phpmyadmin and redis are not so phpmyadmin cannot find that address.