Cannot store state of kafka stream in dockerized application


I am getting the following error when i try to retrieve an entry from my state store: org.apache.kafka.streams.errors.InvalidStateStoreException: Cannot get state store kafka-state-dir because the stream thread is STARTING, not RUNNING.

Here is how i set up the state store:

Materialized.<String, MessageContext, KeyValueStore<Bytes, byte>>as(“kafka-state-dir”)

Also, in a configuration class i define the following bean:
@Bean(name = KafkaStreamsDefaultConfiguration.DEFAULT_STREAMS_CONFIG_BEAN_NAME)
KafkaStreamsConfiguration kStreamsConfig() {
Map<String, Object> props = new HashMap<>();
props.put(APPLICATION_ID_CONFIG, “applicationId”);
props.put(BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
props.put(DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.StringSerde.class);
props.put(DEFAULT_VALUE_SERDE_CLASS_CONFIG, CustomSerdes.messageContextSerde().getClass().getName());
// configure the state location to allow tests to use clean state for every run
props.put(STATE_DIR_CONFIG, “/app/kafka-state-dir”);

    return new KafkaStreamsConfiguration(props);

Here, i am getting the entry from the store:

KafkaStreams kafkaStreams = streamsFactoryBean.getKafkaStreams();
if (kafkaStreams != null) {
ReadOnlyKeyValueStore<String, MessageContext> keyValueStore =
“kafka-state-dir”, QueryableStoreTypes.keyValueStore()));
return keyValueStore.get(correlationId);

Finally this is my dockerfile:
ENV JVM_MEM_ARGS=-Xms128m\ -Xmx2g
ADD ./target/${JAR_FILE} /app/myjar.jar
CMD [“./”, “myjar.jar”]

Note that I am having the above problem only in the dockerized version of my java application. When i run the application as a standalone spring boot application i get no error and i am able to retrieve the entry from the state store.

From inside the container i see that only some of the required state store files are created
ls /app/kafka-state-dir/applicationId:

Whereas when i run it as a standalone spring boot application i see may files:
ls /kafka-state-dir/applicationId:
0_0 0_1 0_2 0_3 kafka-streams-process-metadata
ls /kafka-state-dir/applicationId/0_0/

Do you have any ideas?