-3

I have tried other answers on stackoverflow and github, but none of them are working. When I run the container I get this as the output(Which is the standard "flask run" output)

This is my Dockerfile

FROM alpine:latest

RUN apk add --no-cache python3-dev && pip3 install --upgrade pip 

WORKDIR /app

COPY . /app

RUN pip3 install Flask && pip3 install requests && pip3 install simplejson

EXPOSE 5000
CMD [ "flask", "run" ]

I have tried 0.0.0.0:5000 too but its not working.

batman
  • 53
  • 8
  • Which machine are you working on? Also, can you share the result of running ```docker ps``` – Vishakha Lall Jan 27 '20 at 04:56
  • @VishakhaLall It's MacOS and here's the screenshot of docker ps : https://imgur.com/a/a22F0w2 – batman Jan 27 '20 at 05:02
  • You cannot access anything on port `5000` using hostname or IP address is that your problem. ?? You cannot access anything that is running on localhost inside docker – Sohan Jan 27 '20 at 06:24
  • When you say "I get this as the output", what do you actually get? Your script and `docker ps` probably write out text, not PNG files or links; include that text directly in the question (not a link and never a screenshot of a terminal). – David Maze Jan 27 '20 at 10:11

2 Answers2

0

Run this command to know the IP address of the host. boot2docker ip

Now use this IPAddress along with the port number mapped to your host.

When you spawn a container that is running a process such as a web server, you need to specify what ports to publish from the container to the host, for example

docker run -p 8888:8080 tomcat

this publishes port 8080 from the container to the host’s port 8888

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29
0
  1. You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls).

  2. You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag. This will bind the exposed port to your Docker host on port 80, and it expects the exposed port is 80 too (adjust as necessary with HOST:CONTAINER).

  3. You can ignore exposing anything and just use -p 80:80 in which case this doubles as both exposing AND publishing the port.

Try running,

docker run -d --name <your_ctr_name>-p 5000:5000 <your_image_name>:latest

If you need to bind host,

docker run -d --name container_name -p 10.x.x.100:5000:5000 image_name:latest

If you want to expose the docker using network host,

docker run -d  --network host --name container_name image_name:latest
Sohan
  • 6,252
  • 5
  • 35
  • 56
  • --network host does not work with OSX to access localhost. – Vishakha Lall Jan 27 '20 at 06:46
  • Ohh okay, I have less experience with OSX, can this work `-p 10.x.x.100:5000:5000 ` – Sohan Jan 27 '20 at 06:55
  • Since Docker on Mac runs inherently on a VM (and we unfortunately don't know the IP of the VM) we cannot really expose ports the traditional way. – Vishakha Lall Jan 27 '20 at 06:57
  • I suspect if any firewall is trying to block the access on main host, like we do have this issue in Linux systems – Sohan Jan 27 '20 at 07:07
  • Also I was checking https://docs.docker.com/docker-for-mac/networking/#known-limitations-use-cases-and-workarounds. See if you have similar issues here – Sohan Jan 27 '20 at 07:25