Building Issue When Deploying Django Project To Railway

95 Views Asked by At

When I upload my django project online to railway the following error appears:

Dockerfile:20


18 | ENV NIXPACKS_PATH /opt/venv/bin:$NIXPACKS_PATH

19 | COPY . /app/.

20 | >>> RUN --mount=type=cache,id=s/585223ec-cc75-4dcd-9f98-7ab08bb3e77f-/root/cache/pip,target=/root/.cache/pip python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt

21 |

22 |


ERROR: failed to solve: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install -r requirements.txt" did not complete successfully: exit code: 1

Error: Docker build failed


**My Settings.py**

"""
Django settings for django2 project.

Generated by 'django-admin startproject' using Django 4.2.6.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'core',
    'bootstrap4',
    'stdimage',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django2.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'django2.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

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





# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = os.path.join(BASE_DIR, '/staticfiles/')
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')



"""

i dont know why this error

I don't know if the problem is in the database or in relation to the media, but when I upload the project this error appears, I've already researched several things and I can't find a solution

1

There are 1 best solutions below

0
On

Happens to encounter same error. I found out from searching the web that services on railway generally use ubuntu and packages that are available only for windows may cause the docker build error. I checked my requirements.txt and removed all unneeded packages that are listed automatically when I used pip freeze command and that solves my problem.

see link for reference: https://www.answeroverflow.com/m/1123174381372313670