Pierre de LESPINAY
Pierre de LESPINAY

Reputation: 46218

Dump remote MySQL database from a docker container

I'm trying to dump a remote database into a local docker container's database.

$ docker exec -i my_container \
  mysqldump my_remote_database -h my_remote_host.me -u my_remote_user -p

This gives me the remote dump well

So here are my attempts:

$ docker exec -i my_container \
  mysqldump my_remote_database -h my_remote_host.me -u my_remote_user -p \
| docker exec -i my_container mysql -u my_local_user -pmy_local_password \
      -D my_local_database

$ docker exec -i my_container bash -c \
    "mysqldump my_remote_database -h my_remote_host.pp -u my_remote_user -p \
   | mysql -u my_local_user -pmy_local_password -D my_local_database"

Both don't seem to have any effect on the local database (no error though)

How can I transfer these data ?

Upvotes: 1

Views: 3356

Answers (1)

Ray
Ray

Reputation: 41508

I always like to hammer out problems from inside the container in an interactive terminal.

First, get the cantainer of image running and check to see the following:

  1. If you bash onto the local container docker exec -ti my_container bash, does the remote hostname my_remote_host.me resolve and can you route to it? Use ping or nslookup.
  2. From inside the interactive terminal bash shell can you connect to the remote db? Just try a vanilla mysql cli connect using the credentials
  3. Finally try the dump from inside the interactive terminal and just create a mydump.sql dump file.

Then check that inside the container:

  1. You can connect to the local DB the credetials provided (if using tcp connection not socket the hostname should resolve, but it looks like your local db is using a socket)
  2. See if you can load the dump file using mysql -u my_local_user -pmy_local_password -D mylocaldb < mydump.sql

If this all works then you can start looking at why the pipe is failing, but I suspect the issue may be with one of the resolutions.

I notice you say local database. Is the 'local database' inside the container or on the Docker host running a socket connection?

Upvotes: 2

Related Questions