Why won't my MySQL Podman container run?

I have installed "Development Tools" and run the following commands:

podman pull mysql:latest                # this is pulled from docker.io

podman images                           # lists the correct image

mkdir ~/mysql_data ; cd mysql_data

podman run -d \
--name mysql \
-p 3306:3306 \
-v ~/mysql_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD='My password' \
-e MYSQL_USER=dbuser \
-e MYSQL_PASSWORD='My DB password' \
-e MYSQL_DATABASE=testdb \
mysql:latest

podman ps                               # lists no running containers
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

podman ps -a
CONTAINER ID  IMAGE                           COMMAND     CREATED        STATUS      PORTS                   NAMES
341ff9ebe686  docker.io/library/mysql:latest  mysqld      7 minutes ago  Created     0.0.0.0:3306->3306/tcp  mysql

However, when I try to execute the next command (podman exec -it mysql /bin/bash), I get the following error:

Error: can only create exec sessions on running containers: container state improper

What am I doing wrong?

Thanks.

This is correct, because

the container is not running.

So the point is, why the container didn’t start?

Try to remove the container

podman rm mysql

and run it without the -d[1] option in order to see error messages.

podman run --name mysql -p 3306:3306 -v ~/mysql_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD='My password' -e MYSQL_USER=dbuser -e MYSQL_PASSWORD='My DB password' -e MYSQL_DATABASE=testdb mysql:latest

Or try to start the existing container using the -a[2] option.

podman  start --attach mysql

  1. --detach, -d Detached mode: run the container in the background and print the new container ID. ↩︎

  2. --attach, -a Attach container's STDOUT and STDERR. ↩︎

1 Like

It might be selinux doesn’t like your volume. If so then you need to modify your volume to:

-v ~/mysql_data:/var/lib/mysql:Z
5 Likes

You are a life-saver!! Thank you very much :raised_hands:

1 Like