运行时docker-compose内部的django mysql连接错误

时间:2018-12-02 11:21:26

标签: mysql django docker

Dockerfile

import tkinter as tk

root = tk.Tk()

buttonborder = tk.Frame(root, highlightbackground="#37d3ff",
                                  highlightthickness=3, bd=0)
photoshop = tk.Button(buttonborder, text='Photoshop', fg='#37d3ff')
photoshop.pack()
buttonborder.pack()

root.mainloop()

docker-compose.yml

FROM python:3.6
ENV PYTHONUNBUFFERED 1
WORKDIR /usr/src/govtcareer_api

COPY ./ /usr/src/govtcareer_api

RUN pip install -r requirements.txt

CMD ["/bin/bash"]

Django数据库:

version: "3"

services:
  govtcareer_api:
    container_name: govtcareer
    build: .
    command: "bash -c 'python manage.py migrate --no-input && python manage.py runserver 0.0.0.0:8000'"
    working_dir: /usr/src/govtcareer_api
    ports:
      - "8000:8000"
    volumes:
      - ./:/usr/src/govtcareer_api
    links:
      - mysql

  #db
  mysql:
    image: mysql
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: "freejobalert"
      MYSQL_USER: "root"
      MYSQL_PASSWORD: "Thinkonce"
      MYSQL_ROOT_PASSWORD: "Thinkonce"
      MYSQL_HOST: "mysql"
      MYSQL_PORT: "3306"
      MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

错误:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'freejobalert',
        'USER': 'root',
        'PASSWORD': 'Thinkonce',
        'HOST': 'mysql',
        'PORT': '3306',
    }
}

我正在尝试使用docker-commands将django与docker内部的mysql连接。这是代码和命令。

运行命令“ sudo docker-compose up”时出现连接错误

但是我能够在docker内部访问mysql数据库。

请看看

0 个答案:

没有答案