Reputation: 1641
I'm attempting to start a local Kafka broker but the error shows that permissions are denied when trying to execute a shell script.
When I run docker compose -f docker-compose.dev.yml up
I see the following error Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "./create-kafka-topic.sh": permission denied: unknown
.
version: "3"
services:
kafka:
image: confluentinc/cp-kafka
platform: linux/amd64
container_name: kafka
restart: unless-stopped
ports:
- 9092:9092
- 29092:29092
links:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_LISTENERS: LISTENER_DOCKER://:9092,LISTENER_HOST://:29092
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER://kafka:9092,LISTENER_HOST://localhost:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER:PLAINTEXT,LISTENER_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_TRANSACTION_STATE_LOG_NUM_PARTITIONS: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
zookeeper:
image: confluentinc/cp-zookeeper
platform: linux/amd64
container_name: zookeeper
restart: unless-stopped
ports:
- 2181:2181
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_SYNC_LIMIT: 2
schema-registry:
platform: linux/amd64
image: confluentinc/cp-schema-registry
container_name: schema-registry
ports:
- 8081:8081
links:
- kafka
- zookeeper
environment:
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka:9092
SCHEMA_REGISTRY_HOST_NAME: schema-registry
depends_on:
- kafka
- zookeeper
kafka-topics-creator:
platform: linux/amd64
build:
context: .
dockerfile: Dockerfile.init-kafka.yml
cache_from:
- confluentinc/cp-kafka
depends_on:
- kafka
The Dockerfile.init-kafka.yml
file contains the following:
FROM confluentinc/cp-kafka
WORKDIR /usr/bin
COPY scripts/create-kafka-topics.sh create-kafka-topic.sh
RUN chmod 777 create-kafka-topic.sh
ENTRYPOINT ["./create-kafka-topic.sh"]
and create-kafka-topics.sh
contains the following:
#!/bin/bash
# Add the topic you want to create in KAFKA_TOPICS below
# Make sure to prepend the topic with "dev."
KAFKA_TOPICS=("dev.event.this.is.my.kafka.event")
kafka-topics --bootstrap-server kafka:9092 --list
echo "Start creating default topics..."
for topic in "${KAFKA_TOPICS[@]}"
do
kafka-topics --bootstrap-server kafka:9092 \
--create \
--if-not-exists \
--topic "${topic}" \
--partitions 1 \
--replication-factor 1 \
--config "cleanup.policy=compact"
echo "Created topic ${topic}."
done
echo "All topics have been created!"
kafka-topics --bootstrap-server kafka:9092 --list
I've tried doing chmod +x
on the shell script and it shows that I have the correct permissions but something is telling me the Docker container itself doesn't have access to run the shell script?
Upvotes: 0
Views: 1624
Reputation: 1641
Not sure if this is the correct answer to this general issue but I was able to fix this issue with the following:
docker compose -f docker-compose.yml build --no-cache
and
docker compose -f docker-compose.yml up
.
Upvotes: 1