2

I am creating a service which programmatically creates and runs an OpenVPN Docker container (pschiffe/openvpn which extends kylemanna/openvpn) using the Golang SDK.

At some point in the process, the command easyrsa init-pki is ran in the ovpn_initpki script, which requires user input (typing "yes") to proceed. Is there any way using the SDK that I can either override this or programmatically input "yes" when it's required?

Code currently (error handling removed):

ctx := context.Context()
cli := client.NewClientWithOpts(client.WithAPIVersionNegotiation())

// pull image

// create volume

resp := cli.ContainerCreate(
    ctx,
    &container.Config{
        Image: "pschiffe/openvpn",
        Cmd: []string{"openvpn_initpki"}
        Env: []string{"CA_KEY=xxxxxx","CA_CN=xxxxxx"},
    },
    &container.HostConfig{
        Mounts: []mount.Mount{
            {
                Type: mount.TypeVolume,
                Source: "volume_name",
                Target: "/etc/openvpn",
            },
        },
   }, nil, "")

cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
Andrew Willis
  • 2,289
  • 3
  • 26
  • 53
  • 1
    See [this post](https://stackoverflow.com/questions/58732588/accept-user-input-os-stdin-to-container-using-golang-docker-sdk-interactive-co). Question is edited with the solution afterwards. – hsnkhrmn Jan 05 '20 at 12:02
  • Thanks, I'm currently hacking around it, I'll post a solution if I come to a different method to the one in the post. – Andrew Willis Jan 05 '20 at 12:49

0 Answers0