Docker compose apt command doesn’t run

I have this part in my docker-compose.yaml:

  certbot:
    image: certbot/certbot
    volumes:
      - ./certbot/conf:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
      command: apt-get update && apt-get install python-certbot-nginx

Otherwise certbot does not start the cert creation. When I run docker-compose up, the other containers in the file run correctly, but the certbot container fails with this error:

certbot_1   | Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
certbot_1   | it will attempt to use a webserver both for obtaining and installing the
certbot_1   | certificate.
certbot_1   | certbot: error: unrecognized arguments: apt-get update && apt-get python-certbot-nginx
base_1      |
chatwoot_certbot_1 exited with code 2

Note that the install is missing from the second command. If I change anything else (like remove the apt-get update) the change is reflected in the error log, but the commands never run.

Tried using Dockerfile to RUN the command, the docker-compose.yaml relevant part looks like this:

  certbot:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./certbot/conf:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot

And the Dockerfile:

FROM certbot/certbot
RUN apt-get update && apt-get install -y python-certbot-nginx

The error is now this:

Building certbot
Step 1/2 : FROM certbot/certbot
 ---> 0091bcdbf8c6
Step 2/2 : RUN apt-get update && apt-get install -y python-certbot-nginx
 ---> Running in 64119cd99255
/bin/sh: apt-get: not found
ERROR: Service 'certbot' failed to build : The command '/bin/sh -c apt-get update && apt-get install -y python-certbot-nginx' returned a non-zero code: 127

Any suggestions?

Source: Docker Questions