Not able to access file outside the docker container

I am using fs module to access file outside the container. I have mount volume but it is not working.

Env : Linux ubuntu 18, node 16,

Docker compose file :

version: '3'
services:
  bitovn_bridge:
    container_name: bitovn_bridge
    image: bitovnbridge/bitovn-bridge:1.3
    volumes:
        - "./hostmount/:/var/www/http/docker-config"    
    network_mode: "host"
    environment:
      EMAIL_USER: ${EMAIL_USER}
      EMAIL_PASSWORD: ${EMAIL_PASSWORD}
      CRYPTO_SECRET_KEY: ${CRYPTO_SECRET_KEY}
      AWS_ACCESS_KEY: ${AWS_ACCESS_KEY}
      AWS_SECRET: ${AWS_SECRET}
      AWS_BUCKET_NAME: ${AWS_BUCKET_NAME}
      JWT_SECRET: ${JWT_SECRET}
      ROOT_URL: ${ROOT_URL}
      PORT: ${PORT}
      MONGO_URL: ${MONGO_URL}
      LISTEN_PORT: ${LISTEN_PORT}
      ANNOUNCED_IP: ${ANNOUNCED_IP}
      LISTEN_IP: ${LISTEN_IP}
      IP: ${IP}
      DEBUG: ${DEBUG}
      STUN_SERVER: ${STUN_SERVER}
      TURN_SERVER: ${TURN_SERVER}
      TURN_SERVER_USERNAME: ${TURN_SERVER_USERNAME}
      TURN_SERVER_PASSWORD: ${TURN_SERVER_PASSWORD}


    #ports:
    #  - "3000:3000"
    restart: always

Usecase code

readFile(
    "../../../../../var/www/html/docker-config/docker-compose.yml",
    "utf-8",
    function (err, contents) {
      if (err) {
        console.log(err);
        return;
      }

      const replaced = contents.replace(/1.2/g, "2.0");

      writeFile(
        "../../../../../var/www/html/docker-config/docker-compose.yml",
        replaced,
        "utf-8",
        function (err) {
          console.log(err);
        }
      );
    }
  );

Error: ENOENT: no such file or directory

Why all these …/ ?

Have you tried just:

"/var/www/html/docker-config/docker-compose.yml"

Referring to the files as @terpz suggested sounds much better then ../, but first

What is in that ./hostmount folder? Please, always share what you expect from your code and why. We don’t know anything about your environment, only what you share. For me, it looks very strange to use ./hostmount/ as source dir instead of just using a dot character. The only reason I can imagine is that you wanted to see your yaml file in the container under /hostmount, but then you would have used absolute path like /hostmount so I still don’t understand.

And if we are talking about environment.

I don’t think it matters know, but when you share version numbers, try to share the exact numbers. Ubuntu 18 can be 18.04 or 18.10. No problem, because it really doesn’t matter know, but it can in the future.

yes I have tried "/var/www/html/docker-config/docker-compose.yml".

volumes:
        - "./hostmount/:/var/www/http/docker-config"  

I am confused what I should write in place of “./hostmount/”. Should I write container’s full path, How I can get container’s path.

I want to update/edit file using fs module. And file is stored at " /var/www/http/docker-config"

Ok I will keep in mind all things you have mentioned.

./hostmount folder is empty.
I want to update/edit file using fs module. And file is stored at " /var/www/http/docker-config"

volumes:
        - "./hostmount/:/var/www/http/docker-config"  

I am confused what I should write in place of “./hostmount/”. Should i use “./”

Just to be sure: are you aware that the left side before the collon is a host path (or in case you want to use a named volume, then that), the right side after the collon is the container path? It will bind mount the host path you specified into the container path you specified. Note: when a host path is bind mounted into a container path, it will eclipse the original content of the container path.

You should know if you want to map an emtpy folder into the container path, or if the container path expects your folder to contain pre-existing files. Without knowing your exact use case, every recommendation can be a guess at best…

When you are confused, trying out different configurations and inspecting the containers inside is a good way to learn. Use “bash” command instead of the default command of your container or use the docker run instead of docker compose if you can’t find explanations for compose, becaue almost everything that you can do with Docker Compose, you can do without it. If you understand how volumes work, you can use Docker Compose to describe your containers.

As @meyay wrote, you probably mount an empty folder, so you will not have any docker-compose.yml inside.

It is not completely clear to me, I just hope you don’t want to edit the same compose yaml from the container that runs your container.

update:

What do you think “./hostmount/” means? Where dis you get the isea to use it as source?