Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
How to run Python server on Docker's container

I want to run Python HTTP server on docker container.

My DockerFile looks like this:

FROM continuumio/anaconda3:latest

RUN apt-get -y update
RUN apt-get -y install linux-headers-amd64 build-essential libc-dev gcc

RUN conda install --yes gcc
RUN conda install --yes numpy
RUN conda install --yes scipy
RUN conda install --yes gensim
RUN pip install annoy

RUN conda config --add channels conda-forge
RUN conda install --yes spacy

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ADD my-app.tar /usr/src/app

WORKDIR /usr/src/app/source

I build the image with:

docker build -t my-app-poc .

Start the container and enter command:

docker run -i -t -p 9998:9998

In the Docker image's bash I run the script:

python Service.py

Which starts correctly:

Wed Apr  5 13:09:51 2017 Server Starts - :9998

But when I enter the address on my host:

http://localhost:9998

Nothing happens. I've tried also put EXPOSE 9998 at the end of my DockerFile but it wasn't help.

If I enter docker-machine address on my host:

http://192.168.99.100:9989/

it works. But I want to run that image on regular server, not my local machine - so everything should be exposed to localhost.

I tried it on Windows 7.

Do you have any idea how to run this?

I will be very glad for your help!

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

This may or may not be related, but I cannot add a comment, so a standalone reply you get!

In the Docker container you may have to bind your application to the 0.0.0.0 host. See this link.

It seems to me (though I would have to know more about the app to be certain) that you are looking for a connection on the loop-back interface. This exposes the listener to the local machine only. By contrast, 0.0.0.0 serves to expose the listener to all network interfaces on the machine. Specifially in this case, the docker network adapter. For a more detailed explanation, see this post.

about 4 years ago · Santiago Trujillo Relatório

0

What you described is a normal behavior. Docker images are running in a virtualized environment, therefore cannot share the loopback address. What you need to do is to redirect the traffic from your server to your docker image.

This documentation page should have all the answers you need.

Good Luck!

about 4 years ago · Santiago Trujillo Relatório

0

From https://docs.docker.com/engine/reference/run/#expose-incoming-ports

The -p expose option can also take an ip address. If you want to also bind to 127.0.0.1 instead, it goes there.

try something like: -p 127.0.0.1:9998:9998

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda