connect to external ip with port from django deployed on docker

I have django application with mariadb connect with zk terminal via pyzk liberiry ,
application work fine with local but whe deployed tht with docker and every functionality work fine until start connect with zk terminal I have error Exception: can't reach device (ping 41.32.196.3) application will work with ubuntu and windows

zk tirminal must connect py ip and port (4370)

docker-compose.yaml

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>version: "3.9"
services:
db:
image: mariadb:10.5
restart: unless-stopped
command:
- --default-authentication-plugin=mysql_native_password
env_file:
- ./.env
ports:
- 3308:3306
container_name: "djanzk_db"
build:
context: ./mysql
dockerfile: Dockerfile
web:
build: .
container_name: "djanzk_web"
command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python manage.py runserver 0.0.0.0:8040"
ports:
- "8040:8040"
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- .:/app
- /tmp/app/mysqld:/run/mysqld
depends_on:
- db
env_file:
- ./.env
networks:
- default
#networks:
# outside:
# external: true
</code>
<code>version: "3.9" services: db: image: mariadb:10.5 restart: unless-stopped command: - --default-authentication-plugin=mysql_native_password env_file: - ./.env ports: - 3308:3306 container_name: "djanzk_db" build: context: ./mysql dockerfile: Dockerfile web: build: . container_name: "djanzk_web" command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python manage.py runserver 0.0.0.0:8040" ports: - "8040:8040" extra_hosts: - "host.docker.internal:host-gateway" volumes: - .:/app - /tmp/app/mysqld:/run/mysqld depends_on: - db env_file: - ./.env networks: - default #networks: # outside: # external: true </code>
version: "3.9"

services:
  db:
    image: mariadb:10.5
    restart: unless-stopped
    command:
      - --default-authentication-plugin=mysql_native_password
    env_file:
      - ./.env
    ports:
      - 3308:3306
    container_name: "djanzk_db"
    build:
      context: ./mysql
      dockerfile: Dockerfile

  web:
    build: .
    container_name: "djanzk_web"
    command: sh -c "python3 manage.py migrate --noinput && python3 manage.py collectstatic --noinput && python manage.py runserver 0.0.0.0:8040"
    ports:
      - "8040:8040"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - .:/app
      - /tmp/app/mysqld:/run/mysqld
    depends_on:
      - db
    env_file:
      - ./.env
    networks:
      - default

#networks:
#  outside:
#    external: true

.env

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Django settings
SECRET_KEY=
DEBUG=True
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0 [::1]
# MySQL settings
MYSQL_DATABASE=djaznzk
MYSQL_USER=root
MARIADB_ROOT_PASSWORD=root
MYSQL_PASSWORD=root
MYSQL_PORT=3306
MYSQL_HOST=db
</code>
<code># Django settings SECRET_KEY= DEBUG=True DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0 [::1] # MySQL settings MYSQL_DATABASE=djaznzk MYSQL_USER=root MARIADB_ROOT_PASSWORD=root MYSQL_PASSWORD=root MYSQL_PORT=3306 MYSQL_HOST=db </code>
# Django settings
SECRET_KEY=
DEBUG=True
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 0.0.0.0 [::1]

# MySQL settings
MYSQL_DATABASE=djaznzk
MYSQL_USER=root
MARIADB_ROOT_PASSWORD=root
MYSQL_PASSWORD=root
MYSQL_PORT=3306
MYSQL_HOST=db

Dockerfile

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FROM ubuntu:latest
LABEL authors="ibralsmn"
ENTRYPOINT ["top", "-b"]
# Use an official Python runtime as a parent image
FROM python:3.10
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory
WORKDIR /app
# Install dependencies
COPY requirements.txt /app/
RUN pip install -r requirements.txt
# Copy the project code into the container
COPY . /ap
</code>
<code>FROM ubuntu:latest LABEL authors="ibralsmn" ENTRYPOINT ["top", "-b"] # Use an official Python runtime as a parent image FROM python:3.10 # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 # Set the working directory WORKDIR /app # Install dependencies COPY requirements.txt /app/ RUN pip install -r requirements.txt # Copy the project code into the container COPY . /ap </code>
FROM ubuntu:latest
LABEL authors="ibralsmn"

ENTRYPOINT ["top", "-b"]


# Use an official Python runtime as a parent image
FROM python:3.10

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set the working directory
WORKDIR /app

# Install dependencies
COPY requirements.txt /app/
RUN pip install -r requirements.txt

# Copy the project code into the container
COPY . /ap

datbase section in setting.py

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': config('MYSQL_DATABASE','djaznzk'),
'USER': config('MYSQL_USER','root'),
'PASSWORD': config('MYSQL_PASSWORD','root'),
'PORT': config('MYSQL_PORT','3306'),
'HOST': config('MYSQL_HOST','127.0.0.1'),
}
}
</code>
<code>DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': config('MYSQL_DATABASE','djaznzk'), 'USER': config('MYSQL_USER','root'), 'PASSWORD': config('MYSQL_PASSWORD','root'), 'PORT': config('MYSQL_PORT','3306'), 'HOST': config('MYSQL_HOST','127.0.0.1'), } } </code>
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': config('MYSQL_DATABASE','djaznzk'),
        'USER': config('MYSQL_USER','root'),
        'PASSWORD': config('MYSQL_PASSWORD','root'),
        'PORT': config('MYSQL_PORT','3306'),
        'HOST': config('MYSQL_HOST','127.0.0.1'),
    }
}

view.py connect function

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def test_terminal(request, ip=None, port=None):
conn = None
zk = ZK(ip, port, timeout=5)
print(zk)
try:
conn = zk.connect()
conn.disable_device()
messages.info(request, f'{ip}:{port} Terminal Connection successful')
except Exception as e:
messages.error(request, f'{ip}:{port} Terminal {e}')
raise Exception(e)
finally:
if conn:
conn.disconnect()
return redirect('list_terminal')
</code>
<code>def test_terminal(request, ip=None, port=None): conn = None zk = ZK(ip, port, timeout=5) print(zk) try: conn = zk.connect() conn.disable_device() messages.info(request, f'{ip}:{port} Terminal Connection successful') except Exception as e: messages.error(request, f'{ip}:{port} Terminal {e}') raise Exception(e) finally: if conn: conn.disconnect() return redirect('list_terminal') </code>
def test_terminal(request, ip=None, port=None):
    conn = None
    zk = ZK(ip, port, timeout=5)
    print(zk)
    try:
        conn = zk.connect()
        conn.disable_device()
        messages.info(request, f'{ip}:{port} Terminal Connection successful')
    except Exception as e:

        messages.error(request, f'{ip}:{port} Terminal {e}')
        raise Exception(e)
    finally:
        if conn:
            conn.disconnect()
    return redirect('list_terminal')

I try disable firewall and change network settings in docker file

New contributor

Ibrahim Alsaman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật