How to fix " Error response from daemon: No command specified"?

I’m beginer in Docker and I tryed to deploy my app with HTTPS powered by Traefik by this article.

I did everything according to the instructions for my project, but I got an error: “Error response from daemon: No command specified”.

How can I solve this issue?

app structure::

└── testapp
    ├── app
    │   ├── __init__.py
    │   ├── main.py
    │   ├── services
    │   └── static
    ├── traefik
    │   └── traefik.toml
    ├── docker-compose.yaml
    ├── Dockerfile
    └── requirements.txt

traefic.toml:

[entryPoints]
  [entryPoints.web]
    address = ":80"
  [entryPoints.web.http]
    [entryPoints.web.http.redirections]
      [entryPoints.web.http.redirections.entryPoint]
        to = "websecure"
        scheme = "https"

  [entryPoints.websecure]
    address = ":443"

[accessLog]

[providers]
  [providers.docker]
    exposedByDefault = false

[certificatesResolvers.letsencrypt.acme]
  email = "mymail@mail.com"
  storage= "acme.json"
  [certificatesResolvers.letsencrypt.acme.httpChallenge]
    entryPoint = "web"

docker-compose.yaml:

version: "3"

services:
  app:
    build: .
    labels:
      - traefik.enable=true
      - traefik.http.routers.app-http.rule=Host(`mydomain.com`)
      - traefik.http.routers.app-http.tls=true
      - traefik.http.routers.app-http.tls.certresolver=letsencrypt

  traefik:
    image: traefik:v2.8
    ports:
      - 80:80
      - 443:443
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - $PWD/testapp/traefik/traefik.toml:/etc/traefik/traefik.toml
      - traefik-public-certificates:/certificates

volumes:
  traefik-public-certificates:

Dockerfile:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
COPY ./app  /code/app/
WORKDIR ./code/
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir -r /code/requirements.txt
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"]

When deploying, it does not see the line:

CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"]

How to fix the error “Error response from daemon: No command specified”?

Can you also show how you try to run and where you see the error message exactly?

The error occurs when executing the docker-compose up --build command when I am in the testapp folder

You are using an other Dockerfile. Look at the steps during the build:

  • FROM
  • COPY
  • WORDKIR
  • RUN
  • RUN
  • COPY
  • RUN

and look at the instructions in the Dockerfile

  • FROM
  • COPY
  • WORKDIR
  • COPY
  • RUN
  • CMD

Try to read the file from the terminal:

cat Dockerfile

Do you edit your files on a different machine and synchronize after that?

Yes, I edited Dockerfile. I’ve tried many variations.

Dockerfile now

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
COPY ./app  /code/app/
WORKDIR ./code/
RUN cd /code/app/
RUN ls -lat
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir -r /code/requirements.txt
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"]

and Dockerfile before:

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
COPY ./app  /code/app/
WORKDIR ./code/
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir -r /code/requirements.txt
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "8000"]

in terminal


in this example I changes lines^

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
to
FROM python:3.9

Can you build the image without Docker Compose?

Yes, I can build image using

docker build -t myimage .
docker run -d --name mycontainer -p 80:80 myimage

and my app is deployind.

What is the version of Docker Compose? It should work, but you can try to add some line breaks after the CMD instruction in your Dockerfile. Some apps can’t handle when the last line does not have a line break

I use Docker Compose version v2.10.2
3

I tryed to add some line breaks at the end of the Dockerfile, but it does not work(.