1

I am running an api using elasticsearch, go, and docker. I have an image for elasticsearch, and an image for the HTTP server scheme. I should be able to run docker-compose up, however for whatever reason, the web image is never ran successfully, and returns the same error:

unsupported protocol scheme ""

Below I have shown both the docker-compose.yml file and the Dockerfile. Any help would be greatly appreciated.

services:
  web:
    image: goserver
    build: .
    ports:
      - "8081:8081"

  es01:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.4.0
    environment:
      node.name: es01
      cluster.initial_master_nodes: es01,es02
      cluster.name: docker-cluster
      bootstrap.memory_lock: "true"
      ES_JAVA_OPTS: -Xms1g -Xmx1g
      xpack.security.enabled: false
    ulimits:
      memlock:
        soft: -1
        hard: -1

  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.4.0
    environment:
      node.name: es02
      discovery.seed_hosts: es01
      cluster.initial_master_nodes: es01,es02
      cluster.name: docker-cluster
      bootstrap.memory_lock: "true"
      ES_JAVA_OPTS: -Xms1g -Xmx1g
      xpack.security.enabled: false
    ulimits:
      memlock:
        soft: -1
        hard: -1
FROM golang:1.18-alpine as builder

RUN apk add --no-cache --virtual .build-deps \
    bash \
    gcc \
    git \
    musl-dev

RUN mkdir build
COPY . /build
WORKDIR /build

RUN go get
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o webserver .
RUN adduser -S -D -H -h /build webserver
USER webserver

FROM scratch
COPY --from=builder /build/webserver /app/
WORKDIR /app
EXPOSE 8081
CMD ["./webserver"]

I set the default esaddress in main.go and have it as a flag - flag.StringVar(&esAddresses, "es-addr", "es01:9200,http://es02:9200", "es address")

I then split the default addresses (or whatever you pass through terminal) here

es := newEs(logger, strings.Split(esAddresses, ","))

Finally, I return the es client here

func newEs(l *log.Logger, address []string) *elasticsearch.Client {
    configAdd := elasticsearch.Config{Addresses: address}
    cli, err := elasticsearch.NewClient(configAdd)```
  • It seems like some of your application code is necessary to understand this question. What code is producing that error? Is there somewhere in the code or configuration that's trying to call `http.Get()` or connect to Elasticsearch, with a misconfigured URL? – David Maze Oct 18 '22 at 11:38
  • I edited the original post - scroll down and it's all there – Evan Hassan Oct 18 '22 at 11:50

1 Answers1

0

In this code...

flag.StringVar(&esAddresses, "es-addr", "es01:9200,http://es02:9200", "es address")

The first component (es01:9200) isn't a valid URL. I think you want:

flag.StringVar(&esAddresses, "es-addr", "http://es01:9200,http://es02:9200", "es address")
larsks
  • 277,717
  • 41
  • 399
  • 399
  • thanks for the suggestion but that didn't do it - still getting the same error – Evan Hassan Oct 18 '22 at 12:28
  • In that case it would help if you were to update your question to include an [mcve] -- that is, sufficient code that we can build it locally and reproduce the problem you're asking about. – larsks Oct 18 '22 at 12:31