简体   繁体   中英

how to visit the my falcon app after docker build and docker run?

As a follow up question of Docker run cannot find executable "uwsgi" :

I have successfully executed docker build and docker run with the Dockerfile as:

FROM python:2-onbuild

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# RUN pip install -r ./requirements.txt
RUN pip install uwsgi

EXPOSE 8000

CMD ["/usr/local/bin/uwsgi", "--http", " :8000" , "--wsgi-file", "falconapp.wsgi"]

I know it's running since I saw this output on terminal:

dacao@Das-MacBook-Pro:~/Documents/bitbucket_2/heatmap_api$ docker run -p 8000:8000 image_heatmap
*** Starting uWSGI 2.0.17 (64bit) on [Tue Mar  6 01:57:52 2018] ***
compiled with version: 4.9.2 on 02 March 2018 19:46:35
os: Linux-4.9.60-linuxkit-aufs #1 SMP Mon Nov 6 16:00:12 UTC 2017
nodename: cc47a3a586e7
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /app
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on  :8000 fd 4
spawned uWSGI http 1 (pid: 7)
uwsgi socket 0 bound to TCP address 127.0.0.1:39275 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 2.7.14 (default, Feb 17 2018, 09:47:19)  [GCC 4.9.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1e966f0
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x1e966f0 pid: 1 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 1, cores: 1)

And I'm sure Docker image is running:

dacao@Das-MacBook-Pro:~/Documents/bitbucket_2/heatmap_api$ docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
cc47a3a586e7        image_heatmap       "/usr/local/bin/uwsg…"   16 minutes ago      Up 17 minutes       0.0.0.0:8000->8000/tcp   laughing_nightingale
dacao@Das-MacBook-Pro:~/Documents/bitbucket_2/heatmap_api$ 

Next, I want to check if my app is actually running. I tried the following url on my safari browser:

http://127.0.0.1:8000/healthcheck 
http://localhost:8000/healthcheck 
http://host-ip:8000/healthcheck

But neither worked. All are giving a 'fail to open page' error.
How to visit the my app?

Sorry I am rookie and really new to docker

UPDATE:

I tried docker-machine ip and it gives Error: No machine name(s) specified and no "default" machine exists . I don't understand since I'm sure the image is running - I checked with docker ps and see the CONTAINER ID IMAGE , etc.

I also tried docker-machine ls and it gives empty list: NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS

Am I supposed to create a docker-machine by docker-machine start or docker-machine create default before I do Docker run ... ?

Your HTTP server in container is running on port 8000, so if you want to see it on your host you must publish port with this pattern:

docker run -p <host-port>:<container-port> smaller_runner

So, you must run this if you want to visit your container on your host on port 8000:

docker run -p 8000:8000 smaller_runner

then you can check one of this urls:

http://127.0.0.1:8000/healthcheck
http://localhost:8000/healthcheck
http://host-ip:8000/healthcheck

if you want to run container on background use -dit for it:

docker run -dit --name test -p 8000:8000 smaller_runner

Upon looking at the startup logs, looks like the problem is with uWSGI configuration.

It seems that the server is listening only from 127.0.0.1 which is the localhost inside the docker container. Have you tried setting the HOST to 0.0.0.0 in your uWSGI configuration? And don't forget to bind the port to the host machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM