dockerdocker-composedockerfiledockerhubportainer

Portainer stacks and command line arguments


I have a portainer stack running one container. Lets use microbin as an example. The docker-compose yaml looks like this:

---
version: "3"
services:
  paste:
    image: danielszabo99/microbin:latest
    container_name: microbin
    restart: always
    ports:
     - "8525:8080"
    volumes:
     - /mnt/docker_volumes/microbin-data:/app/pasta_data

This particular container is hosted on docker hub, and the maintainer provides examples of command line arguments that can be appended to the dockerfile to activate various features easily. One example would be:

--no-listing
Disables the /pastalist endpoint, essentially making all pastas private.

So this brings me to my issue. I don't want to maintain my own custom dockerfile, and in the past I have always inserted environment variables into the docker-compose yaml to call features like this. An example would be like this - I have a stack running for Authentik (a sso/saml/idp gateway with a pretty web interface). You can see the "environment:" section and the variables I am calling.

 server:
    image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server}:${AUTHENTIK_TAG:-2022.5.3}
    restart: unless-stopped
    command: server
    environment:
      AUTHENTIK_REDIS__HOST: redis
      AUTHENTIK_POSTGRESQL__HOST: postgresql
      AUTHENTIK_POSTGRESQL__USER: ${PG_USER:-authentik}
      AUTHENTIK_POSTGRESQL__NAME: ${PG_DB:-authentik}
      AUTHENTIK_POSTGRESQL__PASSWORD: ${PG_PASS}
      AUTHENTIK_ERROR_REPORTING__ENABLED: "true"
      # WORKERS: 2
    volumes:
      - ./media:/media
      - ./custom-templates:/templates
      - geoip:/geoip
    env_file:
      - stack.env

So - not knowing how the development side of making these containers and hosting them on docker-hub goes... is there a way for me to use these command line arguments for microbin as environment variables in my docker-compose yaml / stack configuration file, or am I going to have to wait on the maintainer to implement this as a feature? Thanks for your help in advance.


Solution

  • You can pass command line arguments in your docker-compose.yml file using the command attribute. That assumes of course the process started within the Docker image can deal with those, but that seems to be the case for your image and should generally be the case.

    version: "3"
    services:
      paste:
        image: danielszabo99/microbin:latest
        container_name: microbin
        restart: always
        ports:
         - "8525:8080"
        volumes:
         - /mnt/docker_volumes/microbin-data:/app/pasta_data
        command: my command line --args here
    

    See Docker Compose Reference - command for details.