Ubuntu Mysql Docker

I have also tried running a MySQL container with the -d flag then running a fresh ubuntu 14.04 container (docker.io run -it -link mysql:mysql ubuntu:14.04 bash) linked to it. On the Ubuntu container I installed mysql-client through apt-get and tried to connect to the MySQL container on the ip address in MYSQLPORT3306TCPADDR but that doesn. I have also tried running a MySQL container with the -d flag then running a fresh ubuntu 14.04 container (docker.io run -it -link mysql:mysql ubuntu:14.04 bash) linked to it. On the Ubuntu container I installed mysql-client through apt-get and tried to connect to the MySQL container but that doesn't work either.


Posted by: Ben Kellermann
Date: April 13, 2018 11:41AM

Hey Guys -
Recently I set up an Atomic Docker Host (Fedora-based) in my home lab. My plan is to migrate many service applications that I have spread out to it which should give me some base experience with Docker and such. One of the first things I'm trying to do is migrate a mySQL Database over.
I have a mySQL 5.7.21 Database running on an Ubunutu system which I use for my home's Kodi library. I've found that it seems simple to move a database to another server by dumping it, copying, then importing it; I just am not sure how to do that with a mysql Docker Container.
I've already pulled the image by executing 'docker pull mysql' on my Docker host, but am not 100% sure how to proceed beyond that to get the DB imported. Below is what I think I need to do - could someone please verify and correct if needed?
1. Pull the mySQL Docker image (done)
2. Start a new mysql instance by executing something like 'docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag'
3. Copy the database from the Ubuntu host to a path on the Atomic (Docker) host using SCP
4. Import the new database.
I see that the mysql command to import it would be something like
'mysql -u root -p newdatabase < /path/to/newdatabase.sql'
but I'm not sure the best way to go about it with Docker. It seems that I can create a new container to run mySQL command line by executing something like 'docker run -it --link some-mysql:mysql --rm mysql sh -c 'exec mysql -h'$MYSQL_PORT_3306_TCP_ADDR' -P'$MYSQL_PORT_3306_TCP_PORT' -uroot -p'$MYSQL_ENV_MYSQL_ROOT_PASSWORD''
but not sure it's the best way to go about it. If so, how would I reference the file(s) I copied over to the Docker host for import?
Any help would be greatly appreciated - Thanks!

Options:Reply•Quote

Written By

Sorry, you can't reply to this topic. It has been closed.

Ubuntu Docker Mysql 8

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.

It is importent to keep data persistent for containers running databases. Docker provides you option to keep database files persistent over the docker volumes or storing files directly on host machine.

Use one of the below options to keep MySQL data persistent even after recreating or deleting docker containers.

Ubuntu Mysql DockerList

Option 1 – Storing MySQL Data on Docker Volumes

The Docker volumes are preferred mechanism by the Docker for storing persistent data of Docker containers. You can easily create a Docker volume on your host machine and attach to a Docker containers.

Let’s create a docker-compose file on your system with the following content.

docker-compose.yml:

2
4
6
8
10
12
14
db:
container_name:db
MYSQL_ROOT_PASSWORD:my_secret_password
MYSQL_USER:db_user
ports:
volumes:

After creating file, just run the below command to launch container.

Ubuntu Run Mysql Docker

Output:

Ubuntu Mysql Docker Download

In this case the MySQL container creats all files on host machine under ./data/db directory. To view these files, just run below command.