Search code examples
djangodockermariadbdjango-testing

mysql file not found in $PATH error using Docker and Django?


I'm working on using Django and Docker with MariaDB on Mac OS X.

I'm trying to grant privileges to Django to set up a test db. For this, I have a script that executes this code, sudo docker exec -it $container mysql -u root -p. When I do this after spinning up, instead of the prompt for the password for the database, I get this error message,

OCI runtime exec failed: exec failed: container_linux.go:370: starting container process caused: exec: "mysql": executable file not found in $PATH: unknown

On an Ubuntu machine, I can delete the data folder for the database and spin up, spin down, and run the command without the error, but on my Mac, which is my primary machine that I'd like to use, this fix doesn't work. Any ideas? I've had a peer pull code and try it on their Mac and it does the same thing to them! Docker is magic to me.

Here's my docker-compose.yml.

version: "3.3"

networks:
  django_db_net:
    external: false

services:
  django:
    build: ./docker/django
    restart: 'unless-stopped'
    depends_on:
      - db
    networks:
      - django_db_net
    user: "${HOST_USER_ID}:${HOST_GROUP_ID}"
    volumes:
      - ./src:/src
    working_dir: /src/vger
    command: ["/src/wait-for-it.sh", "db:3306", "--", "python", "manage.py", "runserver", "0.0.0.0:8000"]

    ports:
      - "${DJANGO_PORT}:8000"

  db:
    image: mariadb:latest
    user: "${HOST_USER_ID}:${HOST_GROUP_ID}"
    volumes:
      - ./data:/var/lib/mysql
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=this_is_a_bad_password
      - MYSQL_USER=django
      - MYSQL_PASSWORD=django
      - MYSQL_DATABASE=vger
    networks:
      - django_db_net

And my Dockerfile

FROM python:latest

ENV PYTHONUNBUFFERED=1
RUN pip3 install --upgrade pip & \
  pip3 install django mysqlclient
ENV MYSQL_MAJOR 8.0
RUN apt-key adv --keyserver hkp://pool.sks-keyservers.net:80 --recv-keys 8C718D3B5072E1F5 & \
  echo "deb http://repo.mysql.com/apt/debian/ buster mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list & apt-get update & \
  apt-get -y --no-install-recommends install default-libmysqlclient-dev
WORKDIR /src

Solution

  • I fixed it!

    This is really silly, but OS X doesn't like the "$container" so if you explicitly just write the name of container for the database, it works like a charm!