3

I am new to container, below questions might sound stupid.

There are two questions actually.

  1. I have a non-web python application fully tested in VScode without any error, then I use below Dockerfile to build it locally.

     FROM python:3.8-slim
    
     WORKDIR /app
    
     COPY requirements.txt ./
    
     RUN pip install --no-cache-dir -r requirements.txt
    
     COPY . .
    
     CMD ["python", "./mycode.py"]
    

An image was built successfully, but running ended with a TypeError. I have made sure the requirements.txt has same dependency as in my project environment. The error message is "wrong tuple index" which gives me no clue on where the problem could come from a fully tested code. I am stuck here with a weird feeling.

  1. I then tried buildpack with Procfile: worker: python mycode.py An image was built successfully, but docker run could not launch the application with below error. I have no idea about what else beside "worker:" could launch a non-web python application in Procfile. Stuck again!

ERROR: failed to launch: determine start command: when there is no default process a command is required

I searched but all are about web application with "web:" in Procfile. Any help on either question will be appreciated.

Spark
  • 115
  • 4
  • 15

2 Answers2

0

When you start the container, you'll need to pass it the worker process type like this:

$ docker run -it myapp worker

Then it should run the the command you added to the Procfile.

A few other things:

  • Make sure you're using the heroku/python buildpack or another buildpack that includes Procfile detection.
  • Confirm in the build output that the worker process type was created
  • You can put your command as the web: process type if you do not want to add worker to your start command. There's nothing wrong with a web: process that does run web app
codefinger
  • 10,088
  • 7
  • 39
  • 51
0

Thank @codefinger for reminder. with several trials, I finally get my application launched with below command:

    docker run -it --name container_name image_name python mycode.py

In fact docker run command has its format as:

docker run [options] image [command] [arg..]

I suspect even buildpack image has no worker process, it is still possible to use "command" option to launch your application.

However, successfully running image built by buildpack without any error leaves me an increasing weird feeling.
Same code and same requirement.txt file, nothing changed! Why image built by docker build gives me a TypeError? So weird.

Spark
  • 115
  • 4
  • 15