Eric Brown
Eric Brown

Reputation: 1462

Docker mariadb 111 error trying to connect

I have two instances of mariadb that I am trying to run (I need one for backwards compatibility). Here is the docker-compose.yml for both of them:

  db:
    container_name: db
    image: mariadb:latest
    ports:
      - "3306:3306"
    networks:
      devel:
        ipv4_address: 172.19.0.105
    volumes:
      - "${DATA_DIR}/mariadb:/var/lib/mysql"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1
  db2:
    container_name: db2
    image: mariadb:10.2.37
    ports:
      - "3307:3306"
    networks:
      devel:
        ipv4_address: 172.19.0.106
    volumes:
      - "${DATA_DIR}/mariadb2:/var/lib/mysql"
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 1

I can connect to the first one, the one labelled db, no problem, but I get the following error for the second one:

ERROR 2003 (HY000): Can't connect to MySQL server on '172.19.0.106' (111)

Here is the command I am trying to run to access it:

mysql --user=root --host=172.19.0.106 --port=3307

I'm not sure why it can't connect. The information looks correct, but it's not working, so I don't know what I did wrong.

Also, the ${DATA_DIR} is a variable that is apart of a command to start the docker containers, so that is supposed to be there and is correct, in case anyone is wondering.

Update: Here is my docker log for db2:

2021-03-16 21:53:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.2.37+maria~bionic started.
2021-03-16 21:53:54+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-03-16 21:53:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.2.37+maria~bionic started.
2021-03-16 21:53:55 140078898230976 [Note] mysqld (mysqld 10.2.37-MariaDB-1:10.2.37+maria~bionic) starting as process 1 ...
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Uses event mutexes
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Using Linux native AIO
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Number of pools: 1
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Using SSE2 crc32 instructions
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Completed initialization of buffer pool
2021-03-16 21:53:55 140078171240192 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-03-16 21:53:55 140078898230976 [Warning] InnoDB: Failed to set O_DIRECT on file./ibdata1;OPEN: Invalid argument, ccontinuing anyway. O_DIRECT is known to result in 'Invalid argument' on Linux on tmpfs, see MySQL Bug#26662.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Setting log file ./ib_logfile101 size to 50331648 bytes
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Setting log file ./ib_logfile1 size to 50331648 bytes
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: New log files created, LSN=8280100
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Highest supported file format is Barracuda.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: 128 out of 128 rollback segments are active.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: Waiting for purge to start
2021-03-16 21:53:55 140078898230976 [Note] InnoDB: 5.7.33 started; log sequence number 8280588
2021-03-16 21:53:55 140077934044928 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-03-16 21:53:55 140078898230976 [Note] Plugin 'FEEDBACK' is disabled.
2021-03-16 21:53:55 140078898230976 [Note] Server socket created on IP: '::'.
2021-03-16 21:53:55 140078898230976 [Warning] 'proxies_priv' entry '@% root@98c35665786d' ignored in --skip-name-resolve mode.
2021-03-16 21:53:55 140078898230976 [Note] Reading of all Master_info entries succeeded
2021-03-16 21:53:55 140078898230976 [Note] Added new Master_info '' to hash table
2021-03-16 21:53:55 140078898230976 [Note] mysqld: ready for connections.
Version: '10.2.37-MariaDB-1:10.2.37+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2021-03-16 21:53:56 140077934044928 [Note] InnoDB: Buffer pool(s) load completed at 210316 21:53:56

Upvotes: 0

Views: 528

Answers (1)

Martin Osusky
Martin Osusky

Reputation: 845

Use localhost (127.0.0.1) as host instead of the IP address of the dock container because you have a bound port. By default, the mysql client uses the sock file on the local host instead of the tcp protocol. Try the following command:

mysql --user=root --host=127.0.0.1 --port=3307 --protocol=tcp

Upvotes: 1

Related Questions