title: How to create a file using touch in Dockerfile or docker-compose?
body: <p>I want to create an empty DB file using <code>touch</code> by <code>Dockerfile</code> or <code>docker-compose.yml</code> and volume it. Actually, I'm able to create it manually within the container as follows:</p>
  <pre><code>docker exec -it &lt;container-name&gt; bash
  # touch /app/model/modbus.db
  </code></pre>
  <p>Whereas, when I use the following procedure it throws <code>exited with code 0</code> and stops:</p>
  <pre><code>version: '3'
  
  services:
      collector:
          build: .
          image: collector:2.0.0    
          command: bash -c &quot;touch /app/model/modbus.db&quot;  # Note
  #        command: bash /app/bashes/create_an_empty_db.sh
  
          volumes:
            - &quot;./model/modbus.db:/app/model/modbus.db:rw&quot;
  
          tty: true
  </code></pre>
  <p>As well as this, I tried that via <code>Dockerfile</code> without any success either:</p>
  <pre><code>FROM python:3.6-slim
  
  ENV PYTHONUNBUFFERED 1
  
  RUN mkdir /app
  WORKDIR /
  ADD . /app
  RUN touch /app/model/modbus.db  # Note
  CMD python app
  </code></pre>
  <hr />
  <p>[<strong>NOTE</strong>]:</p>
  <p>Also without the <code>command: bash -c &quot;touch /app/model/modbus.db&quot;</code> in the <code>docker-compose.yml</code> which was the cause of <code>exited with code 0</code>; a directory will be created named <code>modbus.db</code> instead of a file due to the following section:</p>
  <pre><code>volumes:
    - &quot;./model/modbus.db:/app/model/modbus.db:rw&quot;
  </code></pre>
  <hr />
  <p>TL;DR:</p>
  <p>How to send a new file from the container to the host which does not exist in the host? (In other words, it is done inside of the container, not in the host)</p>