Reputation: 727
the following file is a docker-compose file. If I execute it via docker-compose up the container create itselfs but is impossible to connect to server, via terminal as via database visual editor. And, if I check the container via docker inspect by terminal, some vaule (i.e. IPaddress) are empty.
If I try to create the same container but manually via docker run command, passing the same parameters via command line, all works perfectly and if I check the container via docker inspect via terminal, all values are correct (also, in particular, IP address) and I can connect to the database so via terminal as via db visual editor.
Why it happens, and why in particular creating the mySql container via this docker-compose file the ipaddress seems empty? Is my docker compose file not correct? I checked several times with
version: '3.6'
services:
mysql:
image: mysql:5.7
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=xyz
ports:
- 127.0.0.1:port_number:port_number
volumes:
- mysql:/var/lib/mysql
- ./mysql-init:/docker-entrypoint-initdb.d
command:
- --max-allowed-packet=64M
volumes:
mysql: {}
EDIT: to reply to 2 users,
1) Port_number was exactly 3306 in the orginal file; 2) The full run command is
sudo docker run --name my_mysql -e MYSQL_ROOT_PASSWORD=my_password -p 3306:3306 mysql:5.7
Upvotes: 2
Views: 210
Reputation: 3890
My guess is the issue is you're listening on IP 127.0.0.1, which is local to the container and therefore can't be accessed remotely. You should listen on 0.0.0.0.
Long version: https://pythonspeed.com/articles/docker-connection-refused/
Upvotes: 1