kafka-docker icon indicating copy to clipboard operation
kafka-docker copied to clipboard

Error: "Service 'kafka' failed to build" during compose-up

Open sabond9 opened this issue 5 years ago • 8 comments

I called command docker-compose up -d to run zookeeper and kafka but I got error:

ERROR: Service 'kafka' failed to build: The command '/bin/sh -c apk add --no-cache bash curl jq docker && chmod a+x /tmp/.sh && mv /tmp/start-kafka.sh /tmp/broker-list.sh /tmp/create-topics.sh /tmp/versions.sh /usr/bin && sync && /tmp/download-kafka.sh && tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt && rm /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz && ln -s /opt/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_HOME} && rm /tmp/ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk && apk add --no-cache --allow-untrusted glibc-${GLIBC_VERSION}.apk && rm glibc-${GLIBC_VERSION}.apk' returned a non-zero code: 2

My docker-compose.yml file looks:

version: '2'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    ports:
      - "2181:2181"
  kafka:
    build: .
    ports:
      - "9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

I'm using docker on Windows 10. How can I fix it?

sabond9 avatar Aug 31 '19 15:08 sabond9

You have only included the part of the log that says a command in the Dockerfile failed. I would suggest including the previous lines that show the output of the RUN command up until it failed.

If you are not customising the image, then I would suggest using a prebuilt image from dockerhub, e.g.

    # build: .
    image: wurstmeister/kafka

If you're still having issues, there are reported problems mounting the docker unix domain socket, this is covered in the FAQ

There are reports that dos2unix can fix some issues - https://github.com/wurstmeister/kafka-docker/pull/195, and a few different fixes in this issue - https://github.com/wurstmeister/kafka-docker/issues/319

General windows issues are labelled with the windows label.

sscaling avatar Sep 01 '19 08:09 sscaling

I have issues running containers on Windows. There is the full log:

PS C:\Users\admin> cd C:\kafka-docker
PS C:\kafka-docker> docker-compose up -d
Building kafka
Step 1/14 : FROM openjdk:8u212-jre-alpine
 ---> f7a292bbb70c
Step 2/14 : ARG kafka_version=2.3.0
 ---> Running in def274f71a04
Removing intermediate container def274f71a04
 ---> 876f55f4f002
Step 3/14 : ARG scala_version=2.12
 ---> Running in 9464e9109b8d
Removing intermediate container 9464e9109b8d
 ---> 90fcfc442f26
Step 4/14 : ARG glibc_version=2.29-r0
 ---> Running in 1bb81a4d2645
Removing intermediate container 1bb81a4d2645
 ---> c5f598c4fb05
Step 5/14 : ARG vcs_ref=unspecified
 ---> Running in 03a860bbbaaf
Removing intermediate container 03a860bbbaaf
 ---> 667c8570cf6d
Step 6/14 : ARG build_date=unspecified
 ---> Running in a6afbda75c17
Removing intermediate container a6afbda75c17
 ---> adaa38eca1ee
Step 7/14 : LABEL org.label-schema.name="kafka"       org.label-schema.description="Apache Kafka"       org.label-schema.build-date="${build_date}"       org.label-schema.vcs-url="https://github.com/wurstmeister/kafka-docker"       org.label-schema.vcs-ref="${vcs_ref}"       org.label-schema.version="${scala_version}_${kafka_version}"       org.label-schema.schema-version="1.0"       maintainer="wurstmeister"
 ---> Running in ca7dec807759
Removing intermediate container ca7dec807759
 ---> 23a18bc406c3
Step 8/14 : ENV KAFKA_VERSION=$kafka_version     SCALA_VERSION=$scala_version     KAFKA_HOME=/opt/kafka     GLIBC_VERSION=$glibc_version
 ---> Running in 5ce8cd0b1751
Removing intermediate container 5ce8cd0b1751
 ---> 996ec61f38f9
Step 9/14 : ENV PATH=${PATH}:${KAFKA_HOME}/bin
 ---> Running in 303c2c503660
Removing intermediate container 303c2c503660
 ---> 92056621296a
Step 10/14 : COPY download-kafka.sh start-kafka.sh broker-list.sh create-topics.sh versions.sh /tmp/
 ---> f656b5237fa9
Step 11/14 : RUN apk add --no-cache bash curl jq docker  && chmod a+x /tmp/*.sh  && mv /tmp/start-kafka.sh /tmp/broker-list.sh /tmp/create-topics.sh /tmp/versions.sh /usr/bin  && sync && /tmp/download-kafka.sh  && tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt  && rm /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz  && ln -s /opt/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_HOME}  && rm /tmp/*  && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk  && apk add --no-cache --allow-untrusted glibc-${GLIBC_VERSION}.apk  && rm glibc-${GLIBC_VERSION}.apk
 ---> Running in 0da87a27a5fa
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/21) Installing ncurses-terminfo-base (6.1_p20190105-r0)
(2/21) Installing ncurses-terminfo (6.1_p20190105-r0)
(3/21) Installing ncurses-libs (6.1_p20190105-r0)
(4/21) Installing readline (7.0.003-r1)
(5/21) Installing bash (4.4.19-r1)
Executing bash-4.4.19-r1.post-install
(6/21) Installing nghttp2-libs (1.35.1-r1)
(7/21) Installing libssh2 (1.8.2-r0)
(8/21) Installing libcurl (7.64.0-r2)
(9/21) Installing curl (7.64.0-r2)
(10/21) Installing libseccomp (2.3.3-r1)
(11/21) Installing runc (1.0.0_rc8-r0)
(12/21) Installing containerd (1.2.7-r0)
(13/21) Installing libmnl (1.0.4-r0)
(14/21) Installing jansson (2.11-r0)
(15/21) Installing libnftnl-libs (1.1.1-r0)
(16/21) Installing iptables (1.6.2-r1)
(17/21) Installing tini-static (0.18.0-r0)
(18/21) Installing device-mapper-libs (2.02.182-r0)
(19/21) Installing docker (18.09.8-r0)
Executing docker-18.09.8-r0.pre-install
(20/21) Installing oniguruma (6.9.1-r0)
(21/21) Installing jq (1.6-r0)
Executing busybox-1.29.3-r10.trigger
OK: 349 MiB in 74 packages
/bin/sh: illegal option -
ERROR: Service 'kafka' failed to build: The command '/bin/sh -c apk add --no-cache bash curl jq docker  && chmod a+x /tmp/*.sh  && mv /tmp/start-kafka.sh /tmp/broker-list.sh /tmp/create-topics.sh /tmp/versions.sh /usr/bin  && sync && /tmp/download-kafka.sh  && tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt  && rm /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz  && ln -s /opt/kafka_${SCALA_VERSION}-${KAFKA_VERSION} ${KAFKA_HOME}  && rm /tmp/*  && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk  && apk add --no-cache --allow-untrusted glibc-${GLIBC_VERSION}.apk  && rm glibc-${GLIBC_VERSION}.apk' returned a non-zero code: 2

I am not customizing the image. How can I use the prebuilt images from dockerhub with docker-compose up -d?

Also, I can't apply the labels "question" and "windows" for my issue.

sabond9 avatar Sep 01 '19 10:09 sabond9

The error is here:

/bin/sh: illegal option -

Which probably means this is failing https://github.com/wurstmeister/kafka-docker/blob/01fbcac3fb6c18e225fb4c10141495df9935e221/download-kafka.sh#L1

How can I use the prebuilt images

As previously mentioned - swap the build directive for the image one

    # build: .
    image: wurstmeister/kafka

sscaling avatar Sep 02 '19 13:09 sscaling

Many thanks. the provided solution solves my problem.

docker on windows 10 Kafka build error with code 2

haamond avatar Nov 27 '19 06:11 haamond

I don't understand the solution to the problem. What needs to be changed exactly? I use Windows 10 Pro @sscaling

its-ghaith avatar Dec 07 '19 20:12 its-ghaith

@ma7amad4088

I don't understand the solution to the problem. What needs to be changed exactly? I use Windows 10 Pro

In docker-compose.yml there is a section:

...
kafka:
    build: .
...

Change build: . to image: wurstmeister/kafka Now docker-compose will not try to build the kafka image from the downloaded repo, but pull an already built one from the docker hub.

isiloron avatar Dec 11 '19 14:12 isiloron

I have Changed build: . to image: wurstmeister/kafka,but there is still something wrong here:

ERROR: for kafka Cannot create container for service kafka: invalid volume specification: '/var/run/docker.sock:/var/run/docker.sock:rw' ERROR: Encountered errors while bringing up the project. How can I solve this problem?

leechee777 avatar Apr 15 '20 16:04 leechee777

Hi, I am trying to customize the image but hitting the same error as the original comment. Could anyone advise how to fix this error

/bin/sh: illegal option -

JaMurphSmi avatar Aug 25 '21 21:08 JaMurphSmi