Docker Community Forums

Share and learn in the Docker community.

Cannot access Mysql Docker Container

I’m trying to access a docker container i have created. Here are the files.


FROM mysql:5.7.24

LABEL description="Immagine DBMS MySql"

ADD dump.sql /docker-entrypoint-initdb.d


The dump.sql creates multiple databases with al the tables for each database. (Is it possible to do this?)


version: '3.3'

    driver: bridge
      driver: default
        - subnet:

      context: .
    image: mysql:5.7.24
    restart: unless-stopped
    container_name: mysqlsrv
      - data-volume:/var/lib/mysql
      - target: 3306
        published: 3390
        protocol: tcp
        mode: host


Here the commands i’m running on terminal:

Starting the container:

PS C:\Sql Server\MySql> docker-compose up                                                                                                                                                     Starting mysqlsrv ... done                                                                                                                                                                    Attaching to mysqlsrv
mysqlsrv | 2020-06-14T11:07:57.454914Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysqlsrv | 2020-06-14T11:07:57.455943Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
mysqlsrv | 2020-06-14T11:07:57.458112Z 0 [Note] InnoDB: PUNCH HOLE support available
mysqlsrv | 2020-06-14T11:07:57.458143Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysqlsrv | 2020-06-14T11:07:57.458148Z 0 [Note] InnoDB: Uses event mutexes
mysqlsrv | 2020-06-14T11:07:57.458151Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysqlsrv | 2020-06-14T11:07:57.458153Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysqlsrv | 2020-06-14T11:07:57.458155Z 0 [Note] InnoDB: Using Linux native AIO
mysqlsrv | 2020-06-14T11:07:57.458319Z 0 [Note] InnoDB: Number of pools: 1
mysqlsrv | 2020-06-14T11:07:57.458429Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysqlsrv | 2020-06-14T11:07:57.459511Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysqlsrv | 2020-06-14T11:07:57.465707Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysqlsrv | 2020-06-14T11:07:57.467263Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysqlsrv | 2020-06-14T11:07:57.478653Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysqlsrv | 2020-06-14T11:07:57.490450Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysqlsrv | 2020-06-14T11:07:57.490629Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysqlsrv | 2020-06-14T11:07:57.505991Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysqlsrv | 2020-06-14T11:07:57.506650Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysqlsrv | 2020-06-14T11:07:57.506677Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysqlsrv | 2020-06-14T11:07:57.507334Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 101589607
mysqlsrv | 2020-06-14T11:07:57.507516Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysqlsrv | 2020-06-14T11:07:57.507702Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqlsrv | 2020-06-14T11:07:57.509875Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200614 11:07:57
mysqlsrv | 2020-06-14T11:07:57.511163Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysqlsrv | 2020-06-14T11:07:57.511449Z 0 [Warning] CA certificate ca.pem is self signed.
mysqlsrv | 2020-06-14T11:07:57.513138Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysqlsrv | 2020-06-14T11:07:57.513304Z 0 [Note] IPv6 is available.
mysqlsrv | 2020-06-14T11:07:57.513313Z 0 [Note]   - '::' resolves to '::';
mysqlsrv | 2020-06-14T11:07:57.513327Z 0 [Note] Server socket created on IP: '::'.
mysqlsrv | 2020-06-14T11:07:57.515152Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysqlsrv | 2020-06-14T11:07:57.515869Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515907Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515915Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515920Z 0 [Warning] 'user' entry 'debian-sys-maint@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515937Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515939Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515946Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.516857Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.516888Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.521147Z 0 [Note] Event Scheduler: Loaded 0 events
mysqlsrv | 2020-06-14T11:07:57.521307Z 0 [Note] mysqld: ready for connections.
mysqlsrv | Version: '5.7.24'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

Checking for active containers:

C:\Users\Myself>docker ps
CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS              PORTS                                         NAMES
ec9f9070939e        mysql:5.7.24                                        "docker-entrypoint.s…"   27 minutes ago      Up About a minute   3390/tcp, 33060/tcp,>3306/tcp   mysqlsrv
64540c9d4bd1        portainer/portainer                                 "/portainer"             7 days ago          Up 46 minutes>9000/tcp                        portainer
0345722e5fc3   "/opt/mssql/bin/nonr…"   6 months ago        Up 46 minutes>1433/tcp                        sqlserver

Then accessing the container and trying login mysql:

C:\Users\Myself>docker exec -ti mysqlsrv bash
root@ec9f9070939e:/# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

The password i’m typing is ‘admin’ as this is the password i’ve specified on the configuration file. I am a beginner with Docker. Anyone know what’s going on?

This is not the first time you start this database. Did you use data-volume already with other settings? The password in the environment variable is only used the first time when MySQL is initialized on an empty volume. The same for the files you place in /docker-entrypoint-initdb.d.

If you are using Docker-for-mac or Docker-for-Windows 18.03+, just connect to your mysql service using the host host.docker.internal (instead of the in your connection string).

As of Docker 18.09.3, this does not work on Docker-for-Linux. A fix has been submitted on March the 8th, 2019 and will hopefully be merged to the code base.