Mario
Mario

Reputation: 4998

How to execute an image of mariadb?

A few days ago I saw myself on the stage of having to install mariadb on my pc that already has mysql, I managed to have both instances thanks to docker. I followed this publication and managed to install docker and an image.

docker run --name mariadb-10.2.10-container -e MYSQL_ROOT_PASSWORD=somepassword -p 127.0.0.1:3311:3306 -d mariadb:10.2.10

The pc did not turn off until suddenly it gave an error today and it was necessary to restart it.

Because I do not have any previous experience with docker now that I try to start the container I do not achieve it.

I share my attempts

docker images return this

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.5                 0da48351c371        4 weeks ago         205MB
mariadb             10.2.10             abcee1d29aac        4 months ago        396MB

When I try

docker run -e MYSQL_ROOT_PASSWORD=somepassword -p 127.0.0.1:3311:3306 -d mariadb:10.2.10

After this I hope to connect to Mariadb through Port 3311 so I worked on my application before the incident. Now the container is running but he seems not to be listening at port 3311, because I am not able to connect from the application or from the MySQL client.

docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
48041cc27494        mariadb:10.2.10     "docker-entrypoint.s…"   7 minutes ago       Up 7 minutes        127.0.0.1:3311->3306/tcp   heuristic_shaw

Now I managed to connect and I see that the problem is that the database does not exist

I have lost my database ?, If so, will there be a way to recover it? I've done something wrong?

By SO user suggestion I show the result of executing the command docker ps -a | grep mariadb

48041cc27494        mariadb:10.2.10     "docker-entrypoint.s…"   About an hour ago   Up About an hour               127.0.0.1:3311->3306/tcp   heuristic_shaw
3af4187383a9        mariadb:10.2.10     "docker-entrypoint.s…"   About an hour ago   Exited (1) About an hour ago                              amazing_stonebraker
f1873e7b117c        mariadb:10.2.10     "docker-entrypoint.s…"   About an hour ago   Exited (1) About an hour ago                              confident_mayer
7d1d1fc27cf0        mariadb:10.2.10     "docker-entrypoint.s…"   About an hour ago   Exited (0) About an hour ago                              admiring_mendeleev
0a828a6ad5f4        mariadb:10.2.10     "docker-entrypoint.s…"   About an hour ago   Exited (1) About an hour ago                              tender_yonath
4802f926ef5d        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    wizardly_mcnulty
673898d10840        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    elated_banach
d444e40e5ccc        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (0) 2 hours ago                                    elated_cori
49fa7950e262        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (0) 2 hours ago                                    gifted_engelbart
987d5e8c80db        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    festive_boyd
6b30e16a91bf        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    wizardly_edison
3aea221c1477        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (0) 2 hours ago                                    inspiring_mcnulty
5e95beb0b4d4        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    sad_hoover
21f9df586582        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    goofy_archimedes
93b6c5db2178        mariadb:10.2.10     "docker-entrypoint.s…"   2 hours ago         Exited (1) 2 hours ago                                    sad_fermi
0fba8554b87f        mariadb:10.2.10     "docker-entrypoint.s…"   4 days ago          Exited (255) 2 hours ago       127.0.0.1:3311->3306/tcp   mariadb-10.2.10-container

Thank you in advance for your help

Upvotes: 1

Views: 203

Answers (1)

docker run creates a new container each time.

So, when your trying to resume the older container with running this, docker run -e MYSQL_ROOT_PASSWORD=somepassword -p 127.0.0.1:3311:3306 -d mariadb:10.2.10

It is actually creating a new container.

So, the work around for you is:

  1. Make sure, the previous container exists with name mariadb-10.2.10-container (as you named your container to this in the 1st command).

If you see the last line of the output of docker ps -a | grep mariadb, that's the ancient container we are looking for!

  1. Now, we have to restart it. But before that we need to stop container 48041cc27494, because it is listening on 127.0.0.1:3311. Run, docker stop 48041cc27494. It should be stopped successfully.

  2. Now start the ancient container! you can run either docker start 0fba8554b87f or docker start $(docker ps -a -q -f name=mariadb-10.2.10-container). Any of these two command should resume your container. You old data should be there. Now you can connect to it just like before.

Further, You should add a restart policy for this container, so that you won't need to restart every time it stops.

Upvotes: 1

Related Questions