Score:0

Cannot access MySQL in container from Windows host

in flag

I am on a Windows 11 Professional workstation. I am running a containerized MySQL in Docker via the instructions at https://hub.docker.com/_/mysql. It says all I need to do is run docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag, replacing tag with the desired tag. I used latest for tag.

To make it accessible to other software on my workstation, I also add a -p 3306:3306 switch. If I do that, the container closes with this error: Enter password: mysqld: Can not perform keyring migration : Invalid --keyring-migration-source option.

What I am left with is either starting MySQL without the -p 3306:3306 switch--it presumptively runs, but nothing can talk to it--or running it with the -p 3306:3306 switch, just to see it fail.

How is this supposed to work?

(Yes, I see similar questions, but none appear to answer this specific issue. Also, I opened a bug report with the container devs, but they stand by their instructions. Yes, this is a workstation, but this will run on a server eventually, and I imagine I'll run into the same issues.)

Score:2
us flag

After deciphering the comments below, it seems you are adding docker run arguments AFTER the image name. These args will be passed to the process inside the container - likely why you are seeing mysqld errors, because you are passing Docker flags to mysqld. The below answer still applies.


I'm not on Windows but this should be platform independent if you're using the standard client to connect and running the server in Docker.

You have the Docker commands right, this is a valid Docker command and works fine, exposing port 3306:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:latest

Docker logs for the container that is started show:

[Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

The problem likely exists somewhere else in your setup, not related to running the container with the -p argument.

Are you sure you're using mysql client to connect with? (not mysqld) ??

Example connection after starting the server:

>> mysql -u root -p -h 127.0.0.1 -P 3306
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
Aren Cambre avatar
in flag
The difference appears to be order of the **-d** and **-p** switches! That is the only difference between your command and mine. If **-p** is before **-d**, it works. Swap places, and they fail. Why??
Rino Bino avatar
us flag
Hmm try again. I just tested and `-d -p 3306:3306` and `-p 3306:3306 -d` work the exact same way. `docker run` can typically take arguments in any order.
dave_thompson_085 avatar
jp flag
@ArenCambre+ the order of options doesn't matter as long as they are (all) BEFORE the image name (mysql:latest). If you put something that should be an option like `-p 3306:3306` after the image name it doesn't work and gives the error you quoted.
Aren Cambre avatar
in flag
@dave_thompson_085 why is that? Can you provide a link to the documentation explaining this?
Aren Cambre avatar
in flag
@RinoBino your experience is like mine, where order of switches isn't almost never important for routine commands like this.
Rino Bino avatar
us flag
@ArenCambre - Dave is correct above. The image name must come last. I should have made that more clear in my comment but you can still swap around the "options/switches" as you please. Just be sure to put the image name last. Everything **after** the image name will be executed "inside" the container. https://docs.docker.com/engine/reference/commandline/run/. I've edited my answer to supply more info on this.
Aren Cambre avatar
in flag
DISREGARD!! I get it now, and it's at the top of the documentation page. The image name exists by itself on the ``docker run`` command. It is not a value of a switch. **-d** is a switch that takes no value. `mysql:tag` is the image name. I was incorrectly reading into the examples that **-d** is followed by a value that was the image name.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.