My Docker problems — Networking & Volumes

Recently I had been working on my own hobby project, there I used docker-compose to run my docker images , and set network_mode: "host" , where I can easily access to all my services via my localhost . I used MySQL database which is running locally on host PC.

All the problems started when I try to deploy my project to actual server. There was a problem in MySQL versions. Therefor I couldnt use mysqldump on it. Also Stored Procedures were not working. I tried some workarounds, but none of them worked for me. Therefore I decided to use MySQL docker image to store data. This was the starting point of a lots of troubles.

Following listed things are issues I faced and solutions I found for them. They may not be the best solution. Yet they worked for me. If you see a mistake I had made, please let me know.

Docker Networks

As I mentioned above, when I want to use MySQL dockrized instance, its obvious that I cant use it on localhost as I have local MySQL running. Thats where I had to think about docker-networks . But I had to define them in docker-compose file.

For this I had used bridge network mode, which is the simplest netwokring mode (for me as it has no config to be done). Official document says:

a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers which are not connected to that bridge network. The Docker bridge driver automatically installs rules in the host machine so that containers on different bridge networks cannot communicate directly with each other.

I have created my own docker network and defined it as a bridge connection. I was happy for a while, then I realized in order to communicate between my container working as frontend to talk with MySQL container , they should be in the same network. But when its in the same network, I can not send requests from my localhost.

Yet another problem. I had to go to reddit for getting a solution and I got many solutions. To be honest this was the one made me to think about docker networks.

I had to place another extra cotainer working as a proxy. For this I used nginx with following config

upstream loadbalancer {
server myservice:7171;
}
server {
location / {
proxy_pass http://loadbalancer;
}
}

MySQL container connection

after fixing all the things (as I thought), tried to conenct my application to MySQL container, as usual, I got error connecting.

Error getting user details Error 1130: Host ‘192.168.32.2’ is not allowed to connect to this MySQL server

I tried to many things to make this thing working. Suddenly a flash hit me..
MySQL does not allow remote root user access. This was already known thing for me, we faced this when we configure MySQL-Router to our Kubernetes cluster at VizuaMatix. Somehow I forgot that.

I had to create a separate user and allow all priviledges to that user.

CREATE USER 'myuser'@'mysqlcontainer' IDENTIFIED BY 'mypass';GRANT ALL ON myDB.* TO 'myuser'@'mysqlcontainer';CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' WITH GRANT OPTION;

File share between Micro-services

I had designed one micro-service to add users using a csv file. When I upload file from my front-end , I got an error saying.

No such file.

As a shortcut and lazy method, I tried adding same file to my project and then copying it to service. But it didnt work. Thats where I had to learn (properly) how to share files between separate microservices in Docker way.

Which I will discuss in later post.

--

--

--

DevOps who is willing to learn and try new things.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Ready-to-go Spark NLP environment in SageMaker Studio

Understanding common Performance Issues in Apache Spark

Why I don’t like physical meetings

15 Free Hosting Providers for Web Developers

Apache + PHP + MSSQL (Windows Server using Command Line)

Conditional rendering of SPFx ListView Command Sets

From Peak to Peak: A Tale from the Trenches

HOW TO GENERATE INFINITE “RANDOM” GROUND TILES, which will disappear after a while IN UNITY.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sachith Muhandiram

Sachith Muhandiram

DevOps who is willing to learn and try new things.

More from Medium

The Only Guide You’ll Ever Need to Install Apache Web Server on CentOS 8

Static Code Analysis

How I Write My Jenkins Files [ Mac and Windows ]

How to edit code and then Fork it to a Repository on Github