• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] MySQL Container / Server in another Container?
#1
Hello,
is it possible to run a mysql server on the netpi?
I thought it should be possible to install it in another container, but i'm always getting some errors.
In my case, its kinda difficult to understand how to install the hypriot/rpi-mysql without having a command line..
If its possible - how to connect to it from another container? (write data from node-red in a table)

best regards 
paul
  Reply
#2
Hello Paul,

yes this is possible. And the idea to let it run in a separate container is also great.

I read the documentation of the MySQL server you are referencing at https://hub.docker.com/r/hypriot/rpi-mysql/. And I can agree that using this container will work.

But there are some things you need to take care about using netPI. The documentation declares everything based on using a command line as you have recognized. This is of course not possible with netPI. So the documentation says you have to define a password with the "-e MYSQL_ROOT_PASSWORD=my-secret-pw" command. This command can be replaced in netPI using the option "env" in the advanced container menu then using at least "MYSQL_ROOT_PASSWORD" as name and "your password" as value. But if you read on the documentation there are other env variables too you can set additionally.

Then of course you have to take care about the port 3306 that is used by this container. This port needs to be exposed when you start the container from port 3306 to port 3306 using the default network/bridge mode.

The documentation says also that another container that wants to access to this MySQL server needs to run the docker command "--link some-mysql:mysql". But as you can read it here https://docs.docker.com/network/links/ the "link" command shall not be used any more. This is why I would do it differently. I would give your container a "hostname" in the network setting dialog for example "paulmysql". Then this container within netPI will get of course an internal IP address but also a name that is constant you can address from other containers.

So from your container then you can use a python script like this:

#!/usr/bin/python
import MySQLdb

db = MySQLdb.connect(host="paulmysql",    # your host, usually localhost
                     user="username",         # your username
                     passwd="password",  # your password
                     db="databasename")        # name of the data base
...


Hope this helps.
You never fail until you stop trying.“, Albert Einstein (1879 - 1955)

  Reply
#3
Thank you, it is much easier when i know where to put the start commands Smile
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  [SOLVED] activate LED1/2 with Node-RED + fieldbus nodes container Christian_Rau 6 90 October-21st-2019, 10:30 AM
Last Post: Armin@netPI
  Cannot start container Magnus 7 37 October-16th-2019, 01:00 PM
Last Post: Armin@netPI
  Generate VLAN interfaces in container FrankJacob 7 46 September-26th-2019, 03:19 PM
Last Post: Armin@netPI
  create container in Portainer v1.12.4 dcatteeu 2 24 September-9th-2019, 12:12 PM
Last Post: dcatteeu
  UMTS/LTE support via USB router/modem sticks in a container Armin@netPI 3 156 September-5th-2019, 02:07 PM
Last Post: Armin@netPI
  Exporting and importing container images Armin@netPI 0 23 August-23rd-2019, 10:39 AM
Last Post: Armin@netPI
  Ready-to-deploy: full featured Node-RED container Armin@netPI 5 78 July-25th-2019, 06:16 AM
Last Post: Armin@netPI
  New Container example "OPC UA server" Armin@netPI 0 17 April-12th-2019, 11:51 AM
Last Post: Armin@netPI
  Official Node-RED container Armin@netPI 0 19 April-5th-2019, 10:39 AM
Last Post: Armin@netPI
  [INFO]Docker DNS server Armin@netPI 0 20 March-7th-2019, 09:02 AM
Last Post: Armin@netPI

Forum Jump:


Users browsing this thread: 1 Guest(s)