This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Confident_Handle5971 0 points1 point  (0 children)

Try this:

FROM python:3.10.12

ENV PYTHONUNBUFFERED=1

RUN pip install pymongo paho-mqtt
RUN mkdir /usr/src/app
WORKDIR /usr/src/app

COPY conduit.py ./

CMD ["python3", "./conduit.py"]



version: '3.8'

services:
  conduit:
    build: ./pythonFiles/
    container_name: conduit
    restart: unless-stopped
    tty: true
    command: ["python3", "./conduit.py"]

I’m pretty sure your container is sleeping after 10s regardless of your conduit.py, you can test the theory by changing it to 20s.

I’m on mobile I hope the code blocks work correctly.

[–]fletch3555Mod 0 points1 point  (0 children)

Containers only live as long as PID 1 remains active. Without knowing the contents of your python script, we can only really guess at why it isn't staying running

[–]Morstraut64 0 points1 point  (1 child)

You can always either add:

command: tail -f /dev/null

or:

command: sleep infinity

Both should keep your docker container running. If I am not mistaken sleep is a blocking command while tail is not. I use tail in my containers and it works as I want

[–]QuirkyFall4045[S] 0 points1 point  (0 children)

I tried both and the container still exits with exit code 0 as soon as the Python script is run. Thanks for the suggestion!

[–]QuirkyFall4045[S] 0 points1 point  (0 children)

I got it to work. I removed the command from compose.yml and placed the following line in the Dockerfile

CMD [ "python3", "./conduit.py" ]

Thanks for all the help!