File: Dockerfile
From ubuntu:focal-20211006
RUN apt-get update
RUN apt-get -y install python3 python3-pip
RUN pip install asyncio
RUN pip install apscheduler==3.7.0
COPY test.py /home/testing/test.py
WORKDIR /home/testing
CMD python3 -u ./test.py
File:test.py
import asyncio
async def main():
print('Comes to main')
if __name__ == '__main__':
try:
print('Comes to Main 1')
asyncio.ensure_future(main())
print('Comes to Main 2')
asyncio.get_event_loop().run_forever()
except (KeyboardInterrupt, SystemExit):
print('Comes to interrupt')
raise
Commands:
sudo docker build -t test:test
sudo docker run test:test
Unable to exit the process with ctrl+c on ubuntu:20.04
Any help would be appreciated
Note: If i use the CMD in Dockerfile to CMD python3 ./test.py
(without -u option) then there are no outputs. And using docker with docker-compose fails to attach