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)```