I'm trying to connect from the MySQL Workbench to my dockerized mysql server. I'm using Windows 10. Here is my Dockerfile:
FROM ubuntu:latest
# package updates & install mysql
RUN apt-get update && apt-get install -y mysql-server
RUN apt-get -y install supervisor
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# bind sql script
ADD musicdb.sql /tmp/musicdb.sql
RUN sed -i -e"s/^bind-address\s*=\s*127.0.0.1/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
EXPOSE 3306
RUN /bin/bash -c "/usr/bin/mysqld_safe &" && \
sleep 5 && \
mysql -u root -e "CREATE DATABASE musicdb" && \
mysql -u root musicdb < /tmp/musicdb.sql
CMD ["/usr/bin/supervisord", "-n"]
I'm using this library to create, run, etc. the container from Java:
https://github.com/spotify/docker-client
My actual method to do this in Java is:
public static void createContainerWithPorts(){
DockerClient docker;
try {
docker = DefaultDockerClient.fromEnv().build();
//PortBindings
Map<String, List<PortBinding>> portBindings = new HashMap<>();
List<PortBinding> hostPorts = new ArrayList<>();
hostPorts.add(PortBinding.of("0.0.0.0", "3306"));
portBindings.put("3306", hostPorts);
HostConfig hostConfig = HostConfig.builder().portBindings(portBindings).build();
ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).image("mysql-container").exposedPorts("3306").build();
//create container
ContainerCreation contaierCreation = docker.createContainer(containerConfig);
String id = contaierCreation.id();
//start container
docker.startContainer(id);
ContainerInfo containerInfo = docker.inspectContainer(id);
System.out.println(containerInfo.toString());
Scanner scanner = new Scanner(System.in);
scanner.next();
docker.killContainer(id);
docker.removeContainer(id);
docker.close();
} catch (DockerCertificateException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (DockerException e) {
e.printStackTrace();
}
}
Java builds the Container fine from the before created Docker Image. When I'm looking on actual running Docker Container it looks that the port binding works. When I access my container with docker exec -it SQLContainer bash it works fine and I can access my SQL server.
When i try to connect with MySQL Workbench, I got the error message shown in the picture below: MySQL Workbench Error Message
Does someone know what I'm doing wrong?
Thanks,