I've a django applicaiton running in docker-compose in local along with an nginx and frontend applicaiton. I've tried to deploy the applicaiton in azure app service using my custom docker image for the django application.
The app deployment was successfull but now i need to run django management command like python manage.py migrate and python manage.py createsuperuser.
I tried to use SSH in my django container, but when i tried to connect its showing
az webapp create-remote-connection --subscription <id> --resource-group <rg-name> -n <app-anme> &
When i tried to connect SSH from azure portal using browser its showing connection closed.
Is there any other way to run django management commands in azure app service with a multi-container application.
Dockercompose
version: "3.8"
services:
web:
image: app.azurecr.io/app:latest
container_name: app
command: uwsgi --ini uwsgi.ini
restart: always
volumes:
- volume:/code
depends_on:
- db
environment:
WEBSITES_ENABLE_APP_SERVICE_STORAGE: TRUE
ports:
- "2222:2222"
nginx:
image: app.azurecr.io/nginx:latest
container_name: nginx
restart: always
volumes:
- volume:/code
environment:
WEBSITES_ENABLE_APP_SERVICE_STORAGE: TRUE
ports:
- "80:80"
- "2222:2222"
depends_on:
- web
db:
image: app.azurecr.io/postgress-12:latest
volumes:
- postgres_data:/var/lib/postgresql/data/
ports:
- 5432:5432
restart: always
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pwd
POSTGRES_DB: db
volumes:
postgres_data:
volume:
driver: local
Dockerfile
FROM python:3.8
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set work directory
WORKDIR /code
# Install dependencies
RUN apt-get update
RUN apt-get -y install libgdal-dev
RUN pip install uwsgi
RUN pip install --upgrade pip
COPY ./requirements.txt /code/
RUN pip install -r requirements.txt
# Copy project
COPY . /code/
# Install OpenSSH and set the password for root to "Docker!".
RUN apt-get install -y openssh-server \
&& echo "root:Docker!" | chpasswd
# Copy the sshd_config file to the /etc/ssh/ directory
COPY sshd_config /etc/ssh/
# Copy and configure the ssh_setup file
RUN mkdir -p /tmp
COPY ssh_setup.sh /tmp
RUN chmod +x /tmp/ssh_setup.sh \
&& (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)
RUN service ssh start
# Open port 2222 for SSH access
EXPOSE 80 2222
SSHd
Port 2222
ListenAddress 0.0.0.0
LoginGraceTime 180
X11Forwarding yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-sha1-96
HostkeyAlgorithms ssh-rsa
PubkeyAcceptedAlgorithms ssh-rsa
StrictModes yes
SyslogFacility DAEMON
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
Subsystem sftp internal-sftp

