2

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 
5
  • Please include the full docker run command you use. Commented Dec 3, 2019 at 14:16
  • just add ports: 3306:3306 Commented Dec 3, 2019 at 14:25
  • I replied to both users by editing my original question. Thank you very much! Commented Dec 3, 2019 at 14:34
  • Is the Compose container actually starting up; a couple of the options are different? The docker inspect output is pretty low-level debugging information that isn't usually useful, and in particular the IP address it reports doesn't work in many extremely common contexts. Commented Dec 3, 2019 at 14:39
  • Thank you very much David; the inspect is not foundamental, is only to report you an additional information. The main problem is that, via docker compose it doesn't work and via command line it works correctly. Have you an idea? Commented Dec 3, 2019 at 14:49

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

2 Comments

The stock mysql image correctly binds to 0.0.0.0; you don't need special configuration for this.
Your theory is correct but I don't think is the solution. Othercases, how were possible that creating the same container by command line; testing this container by sudo docker inspect; checking in the terminal that the IP address is exactly 127.0.0.1 and testing the connection of this one by mysql visual editor extern to the container all works? Thank you very much everycase for your reply, have you other idea?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.