Docker Community Forums

Share and learn in the Docker community.

File not found when use Volume in docker-compose.yml

I want to use volume to mount kafka’s config to my localhost ,but when i check the target folder ,i find only one file,others are deleted ,there is some snapshot to describe

  1. origin folder

  2. latest folder

    only server.properties saved

  3. docker-compose.yml
    kafka1:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka1
    container_name: kafka1
    ports:
    - 9092:9092
    environment:
    KAFKA_BROKER_ID: 1
    KAFKA_ADVERTISED_HOST_NAME: kafka1
    KAFKA_ADVERTISED_PORT: 9092
    KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
    KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092
    KAFKA_LISTENERS: PLAINTEXT://kafka1:9092
    volumes:
    - /Users/sun9/dockerKafkaService/volume/kfkluster/kafka1/logs:/kafka
    - /Users/sun9/dockerKafkaService/volume/kfkluster/kafka1/config:/opt/kafka/config
    external_links:
    - zoo1
    - zoo2
    - zoo3
    networks:
    zookeeper_kafka:
    ipv4_address: 172.19.0.14
    depends_on:
    - zoo1
    - zoo2
    - zoo3

I’m confused about this

Docker version 19.03.13, build 4484c46d9d
MacOS 10.15.6

As the image building stage is complete, you could drop into the docker image and interactively run the commands you are trying to fix.

That should give you some hints

docker run -it web_1 bash
My guess is, as you are setting WORKDIR before you run the COPY, you are probably in the wrong directory.

thanks for your answer,i used these commands to verification
docker run -it -v /Users/sun9/volumeTest:/opt/kafka/config --name kafkaDemo1 -p 9099:9092 -e KAFKA_ZOOKEEPER_CONNECT=localhost:2184 -e KAFKA_LISTENERS=PLAINTEXT://kafkaDemo1:9092 40094a582680 bash

docker run -it --name kafkaDemo2 -p 9099:9092 -e KAFKA_ZOOKEEPER_CONNECT=localhost:2184 -e KAFKA_LISTENERS=PLAINTEXT://kafkaDemo2:9092 40094a582680 bash
and the result is same to older ,there is dockerFile link which i used https://hub.docker.com/r/wurstmeister/kafka/dockerfile,
and i don’t think so COPY can remove my files

You don’t mount the folder from the container to localhost, but the folder from localhost into the container. This means the config files have to be present on your host before you run the compose script.

thanks !!! i get this :grin: