-2

I have a running MySQL container that I have import a lot of data in it (took me a few hours).

Now I want to query the data from this container using a GUI application (DBeaver) on my host. Is there a way that I can expose the network of the running container to host so I can connect to it?

I've been looking around and the most promising option so far is to run docker run a new container with -p tag 3306:3306 but when I do that, all the data imported is gone.

Thank you!

knguyen
  • 594
  • 4
  • 20

2 Answers2

0

I found the answer. Oh, by the way, I don't know why this question was down voted, it's a completely legit question (damn it...)

  1. Find the ID of the container docker ps
  2. Grab that ID, run docker inspect -f '{{ .Mounts }}' <container-id>
  3. From the result, I know that the volume of that container is located here: /var/lib/docker/volumes/simple_wiki_container_devcontainer_my-datavolume/_data
  4. docker run -p 3306:3306 --name new_mysql_with_data -e MYSQL_ROOT_PASSWORD=a_strong_password -v /var/lib/docker/volumes/simple_wiki_container_devcontainer_my-datavolume/_data:/var/lib/mysql -d mysql:lateset

Now I can connect with mysql-client on host 0.0.0.0 on port 3306.

knguyen
  • 594
  • 4
  • 20
-1

Create a new mysql image from running container and run the new image with exposed port . You can do that by using docker commit. Run the new image with exposed port, your data will be saved. use

 docker commit <CONTAINER_ID> mysql-with-data:latest

don't stop running container until commit is done –

Pandey Amit
  • 557
  • 5
  • 17
  • thanks! where is the part in the command above that gets the port `3306` exposed? – knguyen Oct 20 '20 at 09:21
  • I've tried this. But the data is not there... – knguyen Oct 20 '20 at 10:50
  • 1
    `docker commit` is almost never a best practice, and I wouldn't recommend it here. Of note, the standard Docker Hub database images are built in a way where committing the images never keeps their data (it is _always_ in a volume even if you haven't included a `docker run -v` option, and volumes are never committed). – David Maze Oct 20 '20 at 12:12