Hi! I am working on a python project and have adop...
# general
c
Hi! I am working on a python project and have adopted pants to manage the monorepo I am building. In order to deploy the application I am using docker and k8s. As pants has an awesome integration with docker I am trying to build images using pants
docker_image
. The image is building successfully, but when I run a container using the image, it is not able to serve requests to the host (made sure that I am forwarding the correct port). I am using docker on WSL2, and have pasted pants'
BUILD
file and the
dockerfile
I'm using to build the image in the thread. Any ideas on how I can fix this? 🙂
👋 3
dockerfile:
Copy code
FROM python:3.9.10-slim-buster

COPY my-lib/bin-my-lib.pex ./my-lib.pex
RUN PEX_TOOLS=1 ./my-lib.pex venv ./my-lib-venv && rm ./my-lib.pex

CMD "./my-lib-venv/pex"
BUILD file:
Copy code
python_sources(
    name="lib",
    sources=["my-lib/**/*.py"],
)

pex_binary(
    name="bin-my-lib",
    dependencies=[":lib"],
    entry_point="<http://my-lib.app:main|my-lib.app:main>",
    include_tools=True,
    execution_mode="venv",
)

docker_image(
    name="docker",
    dependencies=[":bin-my-lib"],
)
h
What's the
RUN
command doing? I haven't seen anything like that in the Pants docs.
c
I'm creating a venv from the pex and executing the pex file (not an actual pex) in the venv folder (<venv>/pex is a symbolic link to <venv>/main.py)
h
Hi! Is there an error message?
t is not able to serve requests to the host
c
Nope, the request never reaches docker, ie I do not see it in the server access logs. If I curl from the docker container it works and creates an access log
h
I don't see any port expose commands in your Dockerfile
Did you run it attached to the host network or with bridge networking?
I ask because I see you said
made sure that I am forwarding the correct port
Without an
EXPOSE
command in the Dockerfile with the port number, the only way it would work is if you ran it on the host network in which case ports don't need to be explicitly exposed.
c
I use
docker run -p '8080:8080' <image_name>
to run the container
I'll try out
EXPOSE
thanks 👍
🤞 1
h
Yeah, add an
EXPOSE 8080
and I bet you'll see something good
c
Unfortunately that did not solve it. If I curl from outside the container,
curl <http://localhost:8080/>
it responds with
curl: (52) Empty reply from server
h
okay, well I'm mostly speaking from Linux experience. I wouldn't be surprised if there's something funky about this living in a WSL2 space so I think I'm out of ideas. Have you tried running your app not containerized and making sure it works?
1
c
Yup. running outside a container works. I'll try to build the image inside a docker container, which seems like what people do to overcome such weird issues. Are you aware of any examples repos which do that?
Thanks for your help 🙂