Answers: <p>I don't think volumes can be specified with relative paths. 
  Put an absolute path instead of <code>./elastic-stack-ca.p12</code> and you should be fine.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-05-07T15:34:49.893Z
Answers: 2020-05-07T15:34:49.893Z
Answers: Max Uppenkamp
Body: <p>Below is except of my docker-compose.yml file</p>
  
  <p>I am trying to mount from host file inside the container, which works i.e. able to mount
  but then I need to give it permission (my clumsy chown command, below).</p>
  
  <p>I am not sure where to run it as wherever I place my (command: chown,-R,elasticsearch,/usr/share/elasticsearch/config/) </p>
  
  <p>It gives me error that 'no such file or directory' which I think: my code run before volume is attached.</p>
  
  <p>I tried placing it after container_name as well, same 'no such file or directory'</p>
  
  <p>Any advise how to do it?</p>
  
  <pre><code>image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
  container_name: elasticsearch
  
  
  volumes:
    - ./elastic-stack-ca.p12:/usr/share/elasticsearch/config/elastic-stack-ca.p12
    - esdata1:/usr/share/elasticsearch/data
  *command: chown,-R,elasticsearch,/usr/share/elasticsearch/config/*
  </code></pre>
  
  <p>Here is full yml, if it is helpful</p>
  
  <pre><code>    version: '3'
  
  services:
  
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
      container_name: elasticsearch
      command:
       chown,-R,elasticsearch,/usr/share/elasticsearch/config/
      environment:
        - node.name=elasticsearch
        - discovery.seed_hosts=elasticsearch
        - cluster.initial_master_nodes=elasticsearch
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  
      ulimits:
        memlock:
          soft: -1
          hard: -1
      volumes:
        - ./elastic-stack-ca.p12:/usr/share/elasticsearch/config/elastic-stack-ca.p12
        - esdata1:/usr/share/elasticsearch/data
      ports:
        - 9200:9200
  
    kibana:
      image: docker.elastic.co/kibana/kibana:7.6.2
      container_name: kibana
      environment:
        ELASTICSEARCH_URL: "http://elasticsearch:9200"
        ELASTICSEARCH_USERNAME: "kibana"
        ELASTICSEARCH_PASSWORD: "kibana"
      ports:
        - 5601:5601
      depends_on:
        - elasticsearch
  
  volumes:
    esdata1:
      driver: local
  </code></pre>
  
Comments: CC BY-SA 4.0
Comments: 2020-04-30T08:29:30.087Z
Comments: Hi, welcome to the club J Show full logs pls
Comments: Yasen
Comments: CC BY-SA 4.0
Comments: 2020-04-30T12:04:00.290Z
Comments: thanks here is full logs:  elasticsearch    | /usr/local/bin/docker-entrypoint.sh: line 37: /usr/share/elasticsearch/chown,-R,elasticsearch,/usr/share/elasticsearch/config/: No such file or directory
  elasticsearch exited with code 1
Comments: x0rcist
Comments: CC BY-SA 4.0
Comments: 2020-05-02T23:33:28.687Z
Comments: any thoughts I have shared the edited full file.
Comments: x0rcist
Tags: <docker><docker-compose><dockerfile>
Title: Grant access permission to file when mounting from host
UserDisplayName: x0rcist
ThreadText: # Grant access permission to file when mounting from host
  
  (Asked by: username_0 on 2020-04-30)
  
  Below is except of my docker-compose.yml file
  
  I am trying to mount from host file inside the container, which works i.e. able to mount
  but then I need to give it permission (my clumsy chown command, below).
  
  I am not sure where to run it as wherever I place my (command: chown,-R,elasticsearch,/usr/share/elasticsearch/config/)
  
  It gives me error that 'no such file or directory' which I think: my code run before volume is attached.
  
  I tried placing it after container\_name as well, same 'no such file or directory'
  
  Any advise how to do it?
  
  ```
  image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
  container_name: elasticsearch
  
  volumes:
    - ./elastic-stack-ca.p12:/usr/share/elasticsearch/config/elastic-stack-ca.p12
    - esdata1:/usr/share/elasticsearch/data
  *command: chown,-R,elasticsearch,/usr/share/elasticsearch/config/*
  
  ```
  
  Here is full yml, if it is helpful
  
  ```
      version: '3'
  
  services:
  
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
      container_name: elasticsearch
      command:
       chown,-R,elasticsearch,/usr/share/elasticsearch/config/
      environment:
        - node.name=elasticsearch
        - discovery.seed_hosts=elasticsearch
        - cluster.initial_master_nodes=elasticsearch
        - cluster.name=docker-cluster
        - bootstrap.memory_lock=true
        - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
  
      ulimits:
        memlock:
          soft: -1
          hard: -1
      volumes:
        - ./elastic-stack-ca.p12:/usr/share/elasticsearch/config/elastic-stack-ca.p12
        - esdata1:/usr/share/elasticsearch/data
      ports:
        - 9200:9200
  
    kibana:
      image: docker.elastic.co/kibana/kibana:7.6.2
      container_name: kibana
      environment:
        ELASTICSEARCH_URL: "http://elasticsearch:9200"
        ELASTICSEARCH_USERNAME: "kibana"
        ELASTICSEARCH_PASSWORD: "kibana"
      ports:
        - 5601:5601
      depends_on:
        - elasticsearch
  
  volumes:
    esdata1:
      driver: local
  
  ```
  
  **Tags:** docker, docker-compose, dockerfile
  
  > **Comments:**
  > **username_1**: Hi, welcome to the club J Show full logs pls  
  > **username_0**: thanks here is full logs:  elasticsearch    | /usr/local/bin/docker-entrypoint.sh: line 37: /usr/share/elasticsearch/chown,-R,elasticsearch,/usr/share/elasticsearch/config/: No such file or directory elasticsearch exited with code 1  
  > **username_0**: any thoughts I have shared the edited full file.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-05-07. Score: 1
  
  I don't think volumes can be specified with relative paths.
  Put an absolute path instead of `./elastic-stack-ca.p12` and you should be fine.
  
  
  ---
  
  