harpan
harpan

Reputation: 8631

Docker image having apscheduler does not run at all

I am new to docker, so bear with me on this.

I have a app.py file, which simply uses apscheduler to print a sentence on the console. I have followed the structure from the official guide for the python file. When I run the file on my console, it runs as expected. (prints the Tick statement every 10 seconds.)

Now, I want to dockerize it and upload the image to dockerhub. I followed the docker documentations and this is how my DockerFile looks like:

FROM python:3
COPY requirements.txt .
COPY app.py .
RUN pip install --trusted-host pypi.python.org -r requirements.txt
CMD [ "python", "app.py" ]

I have listed the module names in requirements.txt as below:

datetime
apscheduler

The folder is flat. app.py and requirements.txt are in the same level in the directory.

|
|- app.py
|- requirements.txt

I use below commands to build the docker image:

docker build . -t app1:ver3

The docker image builds successfully and shows up when I do

docker images

Problem is, when I run the docker image with

docker run app1:ver3

the image does not show any output.

In fact the image shows as listed when I do docker ps - which is expected but the run command should show me print statements on the console every 10 seconds.

Upvotes: 2

Views: 3040

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146510

There are two things here

You need to use docker run -it app1:ver3

-i: Interactive mode
-t: Enable TTY

I believe just -t also may do the job. See the link below for details

https://docs.docker.com/engine/reference/run/

Upvotes: 3

Related Questions