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.
Related
I'm trying to dockerize our website and I need to be able to connect the MySQL container to an existing database. I don't want to link my app container to a local DB but would rather use a volume to bring the data into the MySQL container. If what I'm trying to do makes sense could someone please help me. Below is my docker-compose file.
version: "3.9"
services:
app:
build:
context: .
dockerfile: dockerfiles/app/Dockerfile
depends_on:
- mysql
container_name: pedestalpro_app
volumes:
- ./:/var/www
- ./dockerfiles/php/local.ini:/usr/local/etc/php/conf.d/local.ini
env_file:
- .env
tty: true
nginx:
image: nginx:alpine
depends_on:
- app
container_name: pedestalpro_nginx
volumes:
- ./public/:/var/www/public
- ./dockerfiles/nginx/conf.d/:/etc/nginx/conf.d/
ports:
- "80:80"
- "443:443"
tty: true
mysql:
image: mysql:5.7.22
container_name: pedestalpro_mysql
volumes:
- pedestalpro_db:/var/lib/mysql
- ./dockerfiles/mysql/my.cnf:/etc/mysql/my.cnf
ports:
- "3307:3306"
env_file:
- .env.mysql
volumes:
pedestalpro_db:
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
flask can not connect mysql in docker compose
in connect string, I already use db service name as host, still can't connect db
My docker-compose.yml:
services:
api:
build:
context: ./api
dockerfile: Dockerfile
volumes:
- './api:/usr/src/app'
ports:
- 5002:5000
environment:
- FLASK_CONFIG=development
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=mysql+pymysql://root:xxxxx#mysql-db:3307/gaojiesi
- SECRET_KEY=ZQbn05PDeA7v11
depends_on:
- mysql-db
links:
- mysql-db
restart: unless-stopped
mysql-db:
image: mysql:8.0
container_name: mysql-db
command: --default-authentication-plugin=mysql_native_password
environment:
- MYSQL_ROOT_PASSWORD=frikyalong
ports:
- "3307:3306"
volumes:
- ./db/mysql/conf/my.cnf:/etc/my.cnf.d/
- ./db/mysql/logs:/logs
- ./db/mysql/data:/var/lib/mysql
you need to change :
DATABASE_URL=mysql+pymysql://root:xxxxx#mysql-db:3307/gaojiesi
to :
DATABASE_URL=mysql+pymysql://root:xxxxx#mysql-db:3306/gaojiesi
port 3307 in not reachable from inside the container
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.
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?