I am trying to move existing project to Docker. I followed this tutorial at M.Academy and followed the setup instructions from Docker on Existing Project
While executing trying to connect with MySQL I am getting this error ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)
I also tried to execute: telnet db 3306
Response:
Trying 172.17.0.1...
telnet: Unable to connect to remote host: Connection timed out
I tried everything but couldn't figure out the problem. I am new to Docker. I am using Ubuntu 18.04 LTE. Haven't changed db.env and got no error on any other step before importing the database.
I further checked and found out that the container is not able to establish connection with MySQL.
P.S. I am successfully able to connect with same MySQL service outside Docker container by using (external MySQL port) mysql -h 127.0.01 -u root -p -P 3306
Steps To Reproduce
Install Docker & Docker Compose on Ubuntu 18.04
Download the Docker Compose template: curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
Replace with existing source code of your existing Magento instance: cp -R ~/Sites/existing src
Execute: docker-compose -f docker-compose.yml up -d
Copy files to container: bin/copytocontainer --all
Import existing database: bin/mysql < /var/www/magento243.sql
Expected Result
Database should have been successfully imported
Actual Result
ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)
P.S. Issue has already been raised here: https://github.com/markshust/docker-magento/issues/589
docker-compose.yml
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-5
ports:
- "80:8000"
- "443:8443"
depends_on:
- "db"
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
- ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
extra_hosts: &appextrahosts
## M1 Mac support to fix Docker delay, see #566
- "app:172.17.0.1"
- "phpfpm:172.17.0.1"
- "db:172.17.0.1"
- "redis:172.17.0.1"
- "elasticsearch:172.17.0.1"
- "rabbitmq:172.17.0.1"
## Selenium support, replace "magento.test" with URL of your site
- "magento.test:172.17.0.1"
phpfpm:
image: markoshust/magento-php:7.4-fpm-11
volumes: *appvolumes
extra_hosts: *appextrahosts
env_file: env/phpfpm.env
db:
image: mariadb:10.4
command: --max_allowed_packet=256M
ports:
- "3306:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
extra_hosts: *appextrahosts
redis:
image: redis:5.0-alpine
ports:
- "6379:6379"
extra_hosts: *appextrahosts
elasticsearch:
image: markoshust/magento-elasticsearch:7.9.3-1
ports:
- "9200:9200"
- "9300:9300"
environment:
- "discovery.type=single-node"
## Set custom heap size to avoid memory errors
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
## Avoid test failures due to small disks
## More info at https://github.com/markshust/docker-magento/issues/488
- "cluster.routing.allocation.disk.threshold_enabled=false"
- "index.blocks.read_only_allow_delete"
extra_hosts: *appextrahosts
rabbitmq:
image: rabbitmq:3.8.22-management-alpine
ports:
- "15672:15672"
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq
environment:
- RABBITMQ_VM_MEMORY_HIGH_WATERMARK=1GB
extra_hosts: *appextrahosts
mailcatcher:
image: sj26/mailcatcher
ports:
- "1080:1080"
extra_hosts: *appextrahosts
## Selenium support, uncomment to enable
#selenium:
# image: selenium/standalone-chrome-debug:3.8.1
# ports:
# - "5900:5900"
# extra_hosts: *appextrahosts
volumes:
appdata:
dbdata:
rabbitmqdata:
sockdata:
ssldata:
This issue was finally resolved by
Removing extra_hosts entries from the YML file
Adding networks in YML
Final docker-compose.yml
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-5
ports:
- "81:8000"
- "444:8443"
depends_on:
- "db"
volumes: &appvolumes
- ~/.composer:/var/www/.composer:cached
- ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
- ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
- appdata:/var/www/html
- sockdata:/sock
- ssldata:/etc/nginx/certs
networks:
- customNetwork
phpfpm:
image: markoshust/magento-php:7.4-fpm-11
volumes: *appvolumes
env_file: env/phpfpm.env
networks:
- customNetwork
db:
image: mariadb:10.4
command: --max_allowed_packet=256M
ports:
- "3307:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
networks:
- customNetwork
redis:
image: redis:5.0-alpine
ports:
- "6379:6379"
networks:
- customNetwork
elasticsearch:
image: markoshust/magento-elasticsearch:7.9.3-1
ports:
- "9201:9200"
- "9301:9300"
environment:
- "discovery.type=single-node"
## Set custom heap size to avoid memory errors
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
## Avoid test failures due to small disks
## More info at https://github.com/markshust/docker-magento/issues/488
- "cluster.routing.allocation.disk.threshold_enabled=false"
- "index.blocks.read_only_allow_delete"
networks:
- customNetwork
rabbitmq:
image: rabbitmq:3.8.22-management-alpine
ports:
- "15672:15672"
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq
environment:
- RABBITMQ_VM_MEMORY_HIGH_WATERMARK=1GB
networks:
- customNetwork
mailcatcher:
image: sj26/mailcatcher
ports:
- "1080:1080"
networks:
- customNetwork
volumes:
appdata:
dbdata:
rabbitmqdata:
sockdata:
ssldata:
networks:
customNetwork:
Related
I want to connect from the sprinboot container to the mysql container but i get this error:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
I am using docker-compose.
This is my docker-compose file:
version: '3'
services:
trips-db:
image: "mysql"
container_name: "trips-db"
volumes:
- newDatabase:/home/sharedData
ports:
- 49152:3306
environment:
- MYSQL_USER=adham
- MYSQL_PASSWORD=123
- MYSQL_ROOT_PASSWORD=admin
trips-app:
build: ./Wasalny_BE
container_name: trips-app
ports:
- 8080:8080
links:
- trips-db
volumes:
newDatabase:
This is my spring boot docker file:
FROM openjdk:8-jdk-alpine
COPY target/wasalny-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
This is my application.properties file:
spring.datasource.url= jdbc:mysql://trips-db:49152/wslny?allowPublicKeyRetrieval=true&useSSL=false&createDatabaseIfNotExist=true
spring.datasource.username= root
spring.datasource.password= admin
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto= update
I run using the following command form the terminal:
docker-compose up -d
--force-recreate
Please create a docker network and attach it into the compose file.
Create a docker Network first like below.
docker network create ext-network
Add network settings into your yaml file as below and give a try
version: '3'
services:
trips-db:
image: "mysql"
container_name: "trips-db"
volumes:
- newDatabase:/home/sharedData
ports:
- 49152:3306
networks:
- ext-network
environment:
- MYSQL_USER=adham
- MYSQL_PASSWORD=123
- MYSQL_ROOT_PASSWORD=admin
trips-app:
build: ./Wasalny_BE
container_name: trips-app
ports:
- 8080:8080
networks:
- ext-network
links:
- trips-db
networks:
ext-network:
external: true
volumes:
newDatabase:
I try to run local docker environment for WhatsApp api. But when I run docker-compose it writes me that MySQL is not up yet - sleeping. I don't have MySql installed on my PC because I think that docker works smth like VM, so it will download mysql and run it. What can be a problem?
docker-compose.yml
version: '3'
volumes:
whatsappMedia:
driver: local
mysqlData:
driver: local
services:
db:
image: mysql:5.7.35
restart: always
environment:
MYSQL_ROOT_PASSWORD: testpass
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
expose:
- "33060"
ports:
- "33060:3306"
volumes:
- mysqlData:/var/lib/mysql
network_mode: bridge
cap_drop:
- MKNOD
wacore:
image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:-2.35.5?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.37.1 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- "db"
network_mode: bridge
links:
- db
cap_drop:
- MKNOD
waweb:
image: docker.whatsapp.biz/web:v${WA_API_VERSION:-2.35.4?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.37.1 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
ports:
- "9090:443"
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
WACORE_HOSTNAME: wacore
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- "db"
- "wacore"
links:
- db
- wacore
network_mode: bridge
cap_drop:
- MKNOD
db.env
WA_DB_ENGINE=MYSQL
WA_DB_HOSTNAME=127.0.0.1
WA_DB_PORT=3306
WA_DB_USERNAME=root
WA_DB_PASSWORD=testpass
WA_DB_CONNECTION_IDLE_TIMEOUT=180000
I edited the docker-compose file, I changed the version from 3 to 3.9, added a default network and deleted network_mode: bridge.
version: '3.9'
volumes:
whatsappMedia:
driver: local
mysqlData:
driver: local
networks:
default:
driver: bridge
services:
db:
image: mysql:5.7.35
restart: always
environment:
MYSQL_ROOT_PASSWORD: testpass
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
expose:
- "33060"
ports:
- "33060:3306"
volumes:
- mysqlData:/var/lib/mysql
networks:
- default
cap_drop:
- MKNOD
wacore:
image: docker.whatsapp.biz/coreapp:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- db
cap_drop:
- MKNOD
waweb:
image: docker.whatsapp.biz/web:v${WA_API_VERSION:?Run docker-compose with env var WA_API_VERSION (ex. WA_API_VERSION=2.39.2 docker-compose <command> <options>)}
command: ["/opt/whatsapp/bin/wait_on_mysql.sh", "/opt/whatsapp/bin/launch_within_docker.sh"]
ports:
- "9090:443"
volumes:
- whatsappMedia:/usr/local/wamedia
env_file:
- db.env
environment:
WACORE_HOSTNAME: wacore
# This is the version of the docker templates being used to run WhatsApp Business API
WA_RUNNING_ENV_VERSION: v2.2.3
ORCHESTRATION: DOCKER-COMPOSE
depends_on:
- db
- wacore
cap_drop:
- MKNOD
This is my docker-compose.yml file for my ubuntu 18.04 system
version: '3.1'
services:
zookeeper:
image: confluentinc/cp-zookeeper
ports:
- 2181
environment:
- ZOOKEEPER_CLIENT_PORT=2181
- ZOOKEEPER_TICK_TIME=2000
- ZOOKEEPER_SYNC_LIMIT=2
kafka:
image: confluentinc/cp-kafka
depends_on:
- zookeeper
ports:
- 9092
- 9094:9094
environment:
- KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
# setup :9092 for access inside the docker network, 9094 for outside (ie host)
- KAFKA_LISTENERS=INTERNAL://kafka:9092,OUTSIDE://kafka:9094
- KAFKA_ADVERTISED_LISTENERS=INTERNAL://kafka:9092,OUTSIDE://localhost:9094
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INTERNAL:PLAINTEXT,OUTSIDE:PLAINTEXT
- KAFKA_INTER_BROKER_LISTENER_NAME=INTERNAL
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1
- KAFKA_NUM_PARTITIONS=10
connect:
network_mode: host
image: logan/kafk-connect:part1
depends_on:
- kafka
ports:
- "8083:8083"
environment:
CONNECT_BOOTSTRAP_SERVERS: localhost:9094
CONNECT_REST_PORT: 8083
CONNECT_GROUP_ID: quickstart-avro
CONNECT_KEY_CONVERTER: io.confluent.connect.avro.AvroConverter
CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
CONNECT_INTERNAL_KEY_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_INTERNAL_VALUE_CONVERTER: org.apache.kafka.connect.json.JsonConverter
CONNECT_REST_ADVERTISED_HOST_NAME: localhost
CONNECT_CONFIG_STORAGE_TOPIC: quickstart-avro-config
CONNECT_OFFSET_STORAGE_TOPIC: quickstart-avro-offsets
CONNECT_STATUS_STORAGE_TOPIC: quickstart-avro-status
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: http://localhost:8081
CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://localhost:8081
CONNECT_LOG4J_ROOT_LOGLEVEL: DEBUG
CONFIG_STORAGE_TOPIC: my_connect_configs
CONNECT_PLUGIN_PATH: /usr/share/java,/etc/kafka-connect/jars/tmp/quickstart/file:/tmp/quickstart/tmp/quickstart/jars:/etc/kafka-connect/jars
mysql:
network_mode: host
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: alphabeta
landoopui:
image: landoop/kafka-connect-ui
links:
- connect
ports:
- "8000:8000"
environment:
CONNECT_URL: http://localhost:8083/
I am running mysql on docker machine .I am able to successfully connect to mysql from remote application ,but I dont know why I am not able to connect to the mysql from my connect container. Although I am able to connect to mysql from remote app and able to connect my connect container from other remote mysql.
I have tried these url "jdbc:mysql://localhost:3306/kafkastudent?user=root&password=alphabeta",
"jdbc:mysql://127.0.0.1:3306/kafkastudent?user=root&password=alphabeta",
"jdbc:mysql://serverip:3306/kafkastudent?user=root&password=alphabeta",
But it always gives an error communication link failure.
Similar question-https://serverfault.com/questions/914991/cant-access-mysql-database-in-docker-container-from-another-container?newreg=77b396cf0ad4480d80e2552282d11743
i have an existing Project ( API - portal - Mysql )
i have used Docker-compose without dockerfile
i publish the API - Portal and put them all in folder and then Docker-compose up
i can reach the api by getting the local values in it
but if i tried to reach mysql trough the API using postman its not working even when i open the frontend website
ConnectionString:
"ConnectionString": "server=xmysql;port=4406;Database=sbs_hani;User ID=hani;Password=123456; persistsecurityinfo=True;Charset=utf8; TreatTinyAsBoolean=false;"
This is my docker-compose file :
version: '3'
services:
xmysql:
container_name: xmysql
hostname: xmysql
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: "123456"
MYSQL_DATABASE: "sbs_hani"
MYSQL_USER: "hani"
MYSQL_PASSWORD: "123456"
ports:
- "3306:4406"
networks:
- xnetwork
volumes:
- data-volume:/var/lib/mysql
- ./hanimysql/sbs_hani.sql:/docker-entrypoint-initdb.d/sbs_hani.sql
xapi:
container_name: xapi
hostname: xapi
image: microsoft/dotnet:latest
# restart: always
tty: true
command: ["dotnet", "/var/lib/volhaniapi/hani.APIs.dll"]
ports:
- "8081:80"
- "8444:443"
networks:
- xnetwork
links:
- xmysql:xmysql
depends_on:
- xmysql
volumes:
- ./haniapi/:/var/lib/volhaniapi/
xportal:
container_name: xportal
hostname: xportal
image: microsoft/dotnet:latest
# restart: always
tty: true
command: ["dotnet", "/var/lib/volhaniportal/hani.Portal.dll"]
ports:
- "8083:80"
- "8446:443"
networks:
- xnetwork
links:
- xmysql:xmysql
depends_on:
- xmysql
volumes:
- ./haniportal/:/var/lib/volhaniportal/
xfront:
container_name: xfront
hostname: xfront
image: nginx:stable-alpine
# restart: always
ports:
- "8082:80"
- "4445:443"
networks:
- xnetwork
links:
- xapi:xapi
depends_on:
- xapi
volumes:
- ./hanifront/:/usr/share/nginx/html
volumes:
data-volume: {}
# xvolmysql:
# driver: "local"
# xvolmongo:
# driver: "local"
# xvolrabbitmq:
# driver: "local"
# xvolstarapi:
# driver: "local"
networks:
xnetwork:
driver: bridge
When you make a connection from one Docker container to another, you always connect to the port the service inside the container is actually listening on. Any ports: mappings are ignored (and in fact you don't need ports: if you don't want the service to be accessible from outside Docker container space).
In your example, you need to change the port number in the connection string to the default MySQL port 3306.
(Consider removing all of the container_name:, hostname:, networks:, and links: blocks in the file. You should have an equivalent container stack with the same functionality; the two most observable differences are that if you directly use docker commands then the container names will be prefixed with the directory names, and the Docker-internal network will be named default. You can still use the service block names like xmysql as host names.)
I have a docker compose file which is basically trying to build a WAMP/LAMP style environment.
Basically, PHPMyAdmin can't seem to connect to MySQL. Looking through answers here, it appeared that it was an issue with legacy auth using MySQL Image 8 so I added:
command: --default-authentication-plugin=mysql_native_password
but that didn't work, so I dropped down to mysql image5.7 and the issue is still present. For some reason, I can't connect to MySQL and I get the error:
mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Try again
and
mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Try again
Here is a copy of my Docker Compose which I don't think is doing anything weird.
Hoping someone can clarify that for me.
version: "3.1"
services:
site:
build: .
ports :
- "80:80"
volumes:
- ./www:/var/www/html/
links:
- database
networks:
- php-network
#######################################
# PHP MY ADMIN
#######################################
phpmyadmin:
build:
context: .
dockerfile: PHPMYADMIN.Dockerfile
restart: always
links:
- database:mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- "8080:80"
environment:
- MYSQL_USERNAME=admin
- MYSQL_PASSWORD=root
networks:
- php-network
#######################################
# MySQL server
#######################################
database:
image: mysql:5.7.25
ports:
- "3306:3306"
container_name: db-mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=test_db
- MYSQL_USER=admin
- MYSQL_PASSWORD=root
networks:
- php-network
networks:
php-network:
driver: bridge
I also saw mention of a "depends on" flag which I tried too but that also failed to allow me to connect. I have had the same error throughout.
It's about the container name.
database:
image: mysql:5.7.25
ports:
- "3306:3306"
- **container_name: db-mysql**
and in your phpcontainer:
phpmyadmin:
build:
context: .
dockerfile: PHPMYADMIN.Dockerfile
restart: always
links:
- database:mysql
environment:
**PMA_HOST: mysql**
PMA_PORT: 3306
you define host as mysql, which in docker network will be unrecognizable.
try switching PMA_HOST to db-mysql.
Sorry for bad formatting.
Also use docker ps to see docker container names and to figure out which hosts do you need to connect.
I've got this working now with the following:
version: "3.1"
services:
www:
build: .
ports:
- "8081:80"
volumes:
- ./www:/var/www/html/
links:
- db
networks:
- default
#######################################
# MySQL server
#######################################
db:
image: mysql:5.7.25
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: test_db
MYSQL_ROOT_PASSWORD: test
volumes:
- ./dump:/docker-entrypoint-initdb.d
- persistent:/var/lib/mysql
networks:
- default
#######################################
# PHP MY ADMIN
#######################################
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- db:db
ports:
- 8080:80
environment:
MYSQL_USER: user
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
volumes:
persistent:
According to your phpmyadmin service configuration, you are trying to reach mysql container by mysql address:
environment:
PMA_HOST: mysql
PMA_PORT: 3306
But container with mysql server is accessible by database or db-mysql addresses.
So, you need to change phpmyadmin service configuration to:
environment:
PMA_HOST: database
PMA_PORT: 3306