OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Running docker with mysql and django backend

  • Thread starter Thread starter Mikssx
  • Start date Start date
M

Mikssx

Guest
My first time dealing with docker and i kinda can't start it up properly. This is my docker-compose.yml file:

Code:
version: "3"
services:
  mysql:
    image: mysql
    container_name: my-mysql
    restart: on-failure
    ports:
      - 3306:3306
    volumes:
      - ./mysql_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ""
      MYSQL_USER: intranet
      MYSQL_PASSWORD: ""
      MYSQL_DATABASE: intranet
      MYSQL_ALLOW_EMPTY_PASSWORD: yes
    healthcheck:
      test:
        [
          "CMD",
          "mysqladmin",
          "ping",
          "-h",
          "localhost",
          "-u",
          "root",
          "-pmy-root-password",
        ]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: my-backend
    restart: on-failure
    volumes:
      - .:/app
    environment:
      DATABASE_URL: mysql2://intranet@mysql:3306/intranet
      SECRET_KEY: x
    ports:
      - 8000:8000
    depends_on:
      - mysql
    command: ["./etc/entry", "web-prod"]

I created in MySQL workbench database 127.0.0.1:3306 with name intranet and code in it:

Code:
CREATE USER 'intranet'@'localhost';
CREATE DATABASE intranet;
GRANT ALL PRIVILEGES ON intranet.* TO 'intranet'@'localhost';
FLUSH PRIVILEGES;

And I got dockerfile like this:

Code:
FROM python:3.7

RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O /usr/local/bin/cloud_sql_proxy \
    && chmod +x /usr/local/bin/cloud_sql_proxy

RUN pip3 install poetry

ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

# -- Install Application into container:
WORKDIR /app

COPY pyproject.toml pyproject.toml
COPY poetry.lock poetry.lock

RUN poetry config virtualenvs.create false && poetry install

COPY . /app

ARG GIT_VERSION
ENV GIT_VERSION $GIT_VERSION
ENTRYPOINT ["/app/etc/entry"]
CMD ["web-prod"]

When running docker-compose up i got this error: django.db.utils.OperationalError: (1045, "Access denied for user 'intranet'@'172.19.0.3' (using password: NO)") Tried searching for this but nothing helped. I will also provide readme from my project:

you need to install:​

Backend​


Make sure you have the intranet database created in MySQL. If not, you might want to use the following commands:

Code:
mysql -u root -p
CREATE USER 'intranet'@'localhost';
CREATE DATABASE intranet;
GRANT ALL PRIVILEGES ON intranet.* TO 'intranet'@'localhost';
FLUSH PRIVILEGES;
exit;

Then:

  1. poetry install
  2. poetry shell
  3. export DATABASE_URL='mysql2://intranet@localhost:3306/intranet'
  4. export SECRET_KEY='x'
  5. ./manage.py migrate
  6. ./manage.py update_perms
  7. ./manage.py createcachetable
  8. ./manage.py runserver

BTW. I write docker-compose file myself that's why I think it my be a problem. I will really appreciate answers that tell me fix step by step, thank you
<p>My first time dealing with docker and i kinda can't start it up properly.
This is my docker-compose.yml file:</p>
<pre><code>version: "3"
services:
mysql:
image: mysql
container_name: my-mysql
restart: on-failure
ports:
- 3306:3306
volumes:
- ./mysql_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_USER: intranet
MYSQL_PASSWORD: ""
MYSQL_DATABASE: intranet
MYSQL_ALLOW_EMPTY_PASSWORD: yes
healthcheck:
test:
[
"CMD",
"mysqladmin",
"ping",
"-h",
"localhost",
"-u",
"root",
"-pmy-root-password",
]
interval: 10s
timeout: 5s
retries: 5

backend:
build:
context: .
dockerfile: Dockerfile
container_name: my-backend
restart: on-failure
volumes:
- .:/app
environment:
DATABASE_URL: mysql2://intranet@mysql:3306/intranet
SECRET_KEY: x
ports:
- 8000:8000
depends_on:
- mysql
command: ["./etc/entry", "web-prod"]

</code></pre>
<p>I created in MySQL workbench database 127.0.0.1:3306 with name intranet and code in it:</p>
<pre><code>CREATE USER 'intranet'@'localhost';
CREATE DATABASE intranet;
GRANT ALL PRIVILEGES ON intranet.* TO 'intranet'@'localhost';
FLUSH PRIVILEGES;
</code></pre>
<p>And I got dockerfile like this:</p>
<pre><code>FROM python:3.7

RUN wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O /usr/local/bin/cloud_sql_proxy \
&& chmod +x /usr/local/bin/cloud_sql_proxy

RUN pip3 install poetry

ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

# -- Install Application into container:
WORKDIR /app

COPY pyproject.toml pyproject.toml
COPY poetry.lock poetry.lock

RUN poetry config virtualenvs.create false && poetry install

COPY . /app

ARG GIT_VERSION
ENV GIT_VERSION $GIT_VERSION
ENTRYPOINT ["/app/etc/entry"]
CMD ["web-prod"]
</code></pre>
<p>When running docker-compose up i got this error: <code>django.db.utils.OperationalError: (1045, "Access denied for user 'intranet'@'172.19.0.3' (using password: NO)")</code>
Tried searching for this but nothing helped. I will also provide readme from my project:</p>
<h4>you need to install:</h4>
<ul>
<li>poetry</li>
<li>[email protected]</li>
<li>python3.7</li>
<li>node v16</li>
</ul>
<h2>Backend</h2>
<p>Make sure you have the <code>intranet</code> database created in MySQL.
If not, you might want to use the following commands:</p>
<pre><code>mysql -u root -p
CREATE USER 'intranet'@'localhost';
CREATE DATABASE intranet;
GRANT ALL PRIVILEGES ON intranet.* TO 'intranet'@'localhost';
FLUSH PRIVILEGES;
exit;
</code></pre>
<p>Then:</p>
<ol>
<li><code>poetry install</code></li>
<li><code>poetry shell</code></li>
<li><code>export DATABASE_URL='mysql2://intranet@localhost:3306/intranet'</code></li>
<li><code>export SECRET_KEY='x'</code></li>
<li><code>./manage.py migrate</code></li>
<li><code>./manage.py update_perms</code></li>
<li><code>./manage.py createcachetable</code></li>
<li><code>./manage.py runserver</code></li>
</ol>
<p>BTW. I write docker-compose file myself that's why I think it my be a problem. I will really appreciate answers that tell me fix step by step, thank you</p>
 

Latest posts

Top