Can't connect to MySQL server using docker-composer

I’m using the docker-toolbox for Windows 7. What I want to do is setup a container with MySQL and load the mysql dump that I have. To do this, I decided to use the docker composer. Here is the content of my Dockerfile and docker-compose.yml


FROM mysql:5.5.55
RUN apt-get update
RUN mkdir /dumps
WORKDIR /dumps
ADD my_dump.sql /dumps/my_dump.sql
RUN mysql -u root -h -e "create database legacy_datasite"
ADD . /dumps


version: '3'
        build: .
            - ~/data-site-mysql/db_data:/var/lib/mysql
        restart: always
            MYSQL_ROOT_PASSWORD: your_password
            MYSQL_DATABASE: legacy_datasite
            - 3306:3306

However, when I created the container using the command

docker-compose run --service-ports db mysql -h -u root -p

It returns the following error:

ERROR 2003 (HY000): Can’t connect to MySQL server on ‘’ (111)

I tried other host like, (docker machine IP),, and even db (service name) because of this suggestion.

Unfortunately, none of them worked. Any suggestions on how to fix this? Thank you very much.

The commands in the Dockerfile are in the internal context of the container, they’re not run from outside. So I don’t think you need to specify -d in the command that you run in the Dockerfile. The image instructions has details on how to initialize the container with .sql file:

1 Like

Thanks. Just decided to follow the instructions in mysql hub page first before proceeding to setting up a composer file.