# How to copy a file to a named volume?

**URL:** <https://forums.balena.io/t/how-to-copy-a-file-to-a-named-volume/4331>\
**Category:** Product support\
**Tags:** docker-compose\
**Created:** [November 5, 2018, 7:40am UTC](https://forums.balena.io/t/how-to-copy-a-file-to-a-named-volume/4331 "2018-11-05T07:40:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/janvda/32/1271_2.png) [@janvda](https://forums.balena.io/u/janvda)\
**Post date:** [November 5, 2018, 7:40am UTC](https://forums.balena.io/t/how-to-copy-a-file-to-a-named-volume/4331/1 "2018-11-05T07:40:42Z")

</div>

I am using a docker compose file with multiple services and named volumes.  
How can I copy a file to such a named volume ?

---

<div class="post-metadata">

**Author:** ![chrisys](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/chrisys/32/1731_2.png) [@chrisys](https://forums.balena.io/u/chrisys)\
**Post date:** [November 5, 2018, 12:53pm UTC](https://forums.balena.io/t/how-to-copy-a-file-to-a-named-volume/4331/4 "2018-11-05T12:53:54Z")

</div>

I’ve achieved this in the past by using a start script in my Dockerfile. Have a look at the script in this application and see how it relates to the named volumes in the Docker compose file.

> <https://github.com/balena-io-playground/balena-sense/blob/master/grafana/start.sh>

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/janvda/32/1271_2.png) [@janvda](https://forums.balena.io/u/janvda)\
**Post date:** [November 5, 2018, 1:02pm UTC](https://forums.balena.io/t/how-to-copy-a-file-to-a-named-volume/4331/5 "2018-11-05T13:02:17Z")

</div>

I have found the issue.

Using COPY in the Dockerfile works if you deploy your application the first time.  
It doesn’t seem to work if you have already deployed your application.

E.g. here below the contents of my Dockerfile

```
FROM arm32v7/telegraf:latest
COPY telegraf.conf /etc/telegraf

```

and here below the contents of my docker-complose.yml file:

```
version: '2'
volumes:
    influx-data:
    influx-config:
    telegraf-config:
services:
  influxdb:
    image: arm32v7/influxdb:latest
    volumes:
      # Mount for influxdb data directory
      - 'influx-data:/var/lib/influxdb'
      # Mount for influxdb configuration
      - 'influx-config:/etc/influxdb/'
    ports:
      # The API for InfluxDB is served on port 8086
      - "8086:8086"
      - "8082:8082"
      # UDP Port
      - "8089:8089"
    restart: always
  telegraf:
    # Full tag list: https://hub.docker.com/r/library/telegraf/tags/
    build : telegraf
    volumes:
      # Mount for telegraf configuration
       - 'telegraf-config:/etc/telegraf'
    pid: "host"
    network_mode: "host"
    privileged: true
    labels:
      io.resin.features.balena-socket: '1'
    depends_on:
      - influxdb
    restart: always
  grafana:
    image: fg2it/grafana-armhf:v5.1.4
    ports:
       - "3000:3000"
    links:
       - influxdb
    restart: always
```

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/janvda/32/1271_2.png) [@janvda](https://forums.balena.io/u/janvda)\
**Post date:** [November 5, 2018, 1:10pm UTC](https://forums.balena.io/t/how-to-copy-a-file-to-a-named-volume/4331/6 "2018-11-05T13:10:00Z")

</div>

Thanks Chris,

You have proposed another solution in [balena-io-playground/balena-sense/blob/master/grafana/start.sh](https://github.com/balena-io-playground/balena-sense/blob/master/grafana/start.sh)  
which also works if your application is already deployed and if multiple services are using the same named volume.

👍👍
