Hi all! I am currently trying to learn Pulumi and ...
# python
b
Hi all! I am currently trying to learn Pulumi and after a few successful attempts with containers on a single host, I was trying to create a simple service within Docker swarm. I already have in my lab a small cluster running docker swarm and wanted to try and deploy containers to it. My code currently looks like this:
Copy code
"""A Python Pulumi program"""
import os
import pulumi
import pulumi_docker as docker

config = pulumi.Config()

pulumi.get_stack()
manager_ip = config.require("manager_ip")

nginx_svc = docker.Service(f"nginx-svc", 
               task_spec=docker.ServiceTaskSpecArgs(container_spec=docker.ServiceTaskSpecContainerSpecArgs(
                   image="nginx:latest"
                   )
                   ),
               endpoint_spec=docker.ServiceEndpointSpecArgs(
                   ports=docker.ServiceEndpointSpecPortArgs(target_port=80,
                                                            published_port=80)
                   ),
               mode = docker.ServiceModeArgs(
                   global_=True,
                   replicated=docker.ServiceModeReplicatedArgs(
                       replicas=1
                       )
                   ),
               opts = pulumi.ResourceOptions(
                   provider=docker.Provider("nginxServiceProvider", host=manager_ip ),
                   
                   )
               )

pulumi.export("nginx_service", nginx_svc)
I have setup the manager_ip in my config file but, when I try to run pulumi up I get: `error: Docker native provider returned an unexpected error from Configure: unable to parse docker host `192.168.192.41`` What am I doing wrong here?
d
I think you need it in the format docker expects in the cli, so prefixed with 'tcp://' https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option
b
Thank you @dry-keyboard-94795! I fixed that but now it sends
failed to connect to any docker daemon
which is progress anyway. I'll investigate what else it needs to be done there to connect to the swarm 🙂 .
ok, just noticed that if I connect to the host using passwordless ssh it moves on. However, now I get
error: docker:index/service:Service resource 'nginx-svc' has a problem: Conflicting configuration arguments: "mode.0.replicated": conflicts with mode.0.global. Examine values at 'nginx-svc.mode.0.replicated'.
error: docker:index/service:Service resource 'nginx-svc' has a problem: Conflicting configuration arguments: "mode.0.global": conflicts with mode.0.replicated. Examine values at 'nginx-svc.mode.0.global'.
And removing global_=True from mode is not helping 😕