How to specify commandline arguments to a docker container in Azure Service Fabric
If I am not mistaken the <ContainerHostEntryPointType>/<Commands>
in the element is what you are looking for.
As per ServiceManifest.xml
schema:
Pass a comma delimited list of commands to the container.
The schema excerpt:
<xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/2011/01/fabric" name="ContainerHostEntryPointType"><xs:sequence> <!--container image name--> <xs:element name="ImageName" type="xs:string"> <xs:annotation> <xs:documentation>The repo and image on https://hub.docker.com or Azure Container Registry.</xs:documentation> </xs:annotation> </xs:element> <!--comma delimited list of commands for container--> <xs:element name="Commands" type="xs:string" minOccurs="0" maxOccurs="1"> <xs:annotation> <xs:documentation>Pass a comma delimited list of commands to the container.</xs:documentation> </xs:annotation> </xs:element> <xs:element name="EntryPoint" type="xs:string" minOccurs="0" maxOccurs="1"/> <xs:element name="FromSource" type="xs:string" minOccurs="0" maxOccurs="1"/></xs:sequence>
As Oleg has explained correctly, you have to specify your parameters in the ServiceManifest.xml alongside the container image name in the <Commands>
element.
What gave me troubles was correctly passing an argument with its value(s). What I found out is Service Fabric will wrap your commands into double quotes if a whitespace is present. In this case you have to replace the whitespaces with commas.
For example, I have a custom Dockerfile with the following entrypoint definition in exec format:
ENTRYPOINT ["redis-server.exe", "C:\\Redis\\redis.docker.conf"]
I wanted to pass --slaveof my-redis-master-instance 6379
as an argument to my docker container (where 6379 is the port of the master). The following service manifest would result in an error:
<EntryPoint> <ContainerHost> <ImageName>myrepository.azurecr.io/my.servicefabric.redis:3.</ImageName> <Commands>--slaveof my-redis-master-instance 6379</Commands> </ContainerHost></EntryPoint>
The reason is Service Fabric does wrap the command into quotes and then passes this to the docker image where it is interpreted as a single argument and causes an error.
Like already explained above, the solution is to replace the whitespaces with commas. Now Service Fabric passes the arguments separately.
<EntryPoint> <ContainerHost> <ImageName>myrepository.azurecr.io/my.servicefabric.redis:3.2.100</ImageName> <Commands>--slaveof,my-redis-master-instance,6379</Commands> </ContainerHost></EntryPoint>
For clarification, in my case I used Service Fabric for Windows with Containers based on Nanoserver 1803.