Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

django - Docker "is not a valid port number or address:port pair."

I am new in docker. I want to run my django app on port 9000. After command docker-compose up I am getting this message

Creating motion_full_version_backend_1 ... done
Attaching to motion_full_version_backend_1
backend_1  | Unknown command: 'makemigrations
'. Did you mean makemigrations?
backend_1  | Type 'manage.py help' for usage.
backend_1  | Unknown command: 'migrate
'. Did you mean migrate?
backend_1  | Type 'manage.py help' for usage.
" is not a valid port number or address:port pair.*

My Dockerfile :

FROM continuumio/miniconda3:latest

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

RUN apt-get update && apt-get upgrade -y && apt-get install -qqy 
        wget 
        bzip2 
        graphviz

RUN mkdir -p /backend

COPY ./backend/requirements.yml /backend/requirements.yml

# Create environment
RUN /opt/conda/bin/conda env create -f /backend/requirements.yml

# Add env path to environment
ENV PATH /opt/conda/envs/backend/bin:$PATH
# Activate interpreter
RUN echo "source activate backend" >~/.bashrc

# Create a scripts folder
RUN mkdir -p /scripts
COPY ./scripts /scripts
RUN chmod +x ./scripts*


COPY ./backend /backend

WORKDIR /backend

I am using script to run it

python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:9000 

my docker-compose.yml looks like this

version: '3'

services:
  backend:
    image: backend:latest
    restart: always
    env_file:
      - ./envs/dev.env
    command: 'sh /scripts/dev.sh'
    ports:
      - "9000:9000"

Any Ideas what I am doing wrong?

question from:https://stackoverflow.com/questions/65644913/docker-is-not-a-valid-port-number-or-addressport-pair

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your script has windows linefeeds within it, e.g. the you see in the output:

makemigrations

Since docker is running this command within a Linux environment, you need to adjust your script linefeeds for the Linux (without any ). Linux sees those carriage returns as part of the string in the command you are running or port number you are passing. Adjust the linefeeds in your editor or using a tool like dos2unix.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...