# Shared volumes in freestyle composition

**URL:** <https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156>\
**Category:** Pipeline Steps\
**Created:** [October 9, 2019, 7:21am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156 "2019-10-09T07:21:30Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![xtrntr](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/xtrntr/32/148_2.png) [@xtrntr](https://community.codefresh.io/u/xtrntr)\
**Post date:** [October 9, 2019, 7:21am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/1 "2019-10-09T07:21:30Z")

</div>

```auto
   run_integration_tests:
     title: Test pipeline
     stage: test-build
     working_directory: IMAGE_WORK_DIR
     image: '${{build_scheduler}}'
     commands:
       - ls
       - ./integration-test.sh
     services:
       volumes:
         ${{CF_VOLUME}}:
           external: true
       composition:
         postgres:
           image: postgres:9.5
           environment:
             - POSTGRES_DB=airflow
             - POSTGRES_PASSWORD=Password123
             - POSTGRES_USER=postgres
             - TZ=Asia/Singapore
         pipeline_app_1:
           image: '${{build_mock_app}}'
           volumes:
             - ${{CF_VOLUME}}:/app/output
           command: bash -c "pwd && ls && echo 'Finished tests' > test_result.txt"

```

gives this error:

```auto
ERROR: Named volume "pipeline_5d6e1fa1a6c4390f0b463fcc_trigger_5d6e200a2287a2849ea5f4fc:/app/output:rw" is used in service "pipeline_app_1" but no declaration was found in the volumes section.

```

---

<div class="post-metadata">

**Author:** ![mustafa\_turab\_ali](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/mustafa_turab_ali/32/38_2.png) [@mustafa\_turab\_ali](https://community.codefresh.io/u/mustafa_turab_ali)\
**Post date:** [October 9, 2019, 8:45am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/2 "2019-10-09T08:45:34Z")

</div>

try:  
volumes:  
- ${{CF\_VOLUME}}:/codefresh/volume/

---

<div class="post-metadata">

**Author:** ![xtrntr](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/xtrntr/32/148_2.png) [@xtrntr](https://community.codefresh.io/u/xtrntr)\
**Post date:** [October 9, 2019, 9:32am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/3 "2019-10-09T09:32:30Z")

</div>

Cannot start composition with warnings [“Volume mapping is not supported, try use: /app/output”]

---

<div class="post-metadata">

**Author:** ![todaywasawesome](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/todaywasawesome/32/91_2.png) [@todaywasawesome](https://community.codefresh.io/u/todaywasawesome)\
**Post date:** [October 9, 2019, 10:45pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/4 "2019-10-09T22:45:07Z")

</div>

Haven’t tried it myself but this page shows using `${{CF_VOUME_NAME}}` instead [Shared volumes of service from composition step for other yml steps · Codefresh | Docs](https://codefresh.io/docs/docs/yaml-examples/examples/shared-volumes-of-service-from-composition-step-for-other-yml-steps/)

---

<div class="post-metadata">

**Author:** ![xtrntr](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/xtrntr/32/148_2.png) [@xtrntr](https://community.codefresh.io/u/xtrntr)\
**Post date:** [October 10, 2019, 2:54am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/5 "2019-10-10T02:54:13Z")

</div>

CF\_VOLUME\_NAME also yields the same error.

---

<div class="post-metadata">

**Author:** ![evanx9](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/evanx9/32/156_2.png) [@evanx9](https://community.codefresh.io/u/evanx9)\
**Post date:** [October 16, 2019, 5:18pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/6 "2019-10-16T17:18:33Z")

</div>

I believe you are hitting a similar issue as we did at [Codefresh](https://support.codefresh.io/hc/en-us/requests/1356)

This was the response from **Codefresh** :

> We have certain volume declarations in compositions that we support and some others that we don’t.
> 
> We DO NOT support absolute path mappings:
> 
> - /opt/data:/var/lib/mysql
> 
> But we do support relative paths:
> 
> - ./cache:/tmp/cache
> 
> Which are relative to the location of the compose file.

This is why the variable referenced used is `{{CF_VOLUME_NAME}}` in the form of: `${{CF_VOLUME_NAME}}:${{CF_VOLUME_PATH}}'`

---

<div class="post-metadata">

**Author:** ![xtrntr](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/xtrntr/32/148_2.png) [@xtrntr](https://community.codefresh.io/u/xtrntr)\
**Post date:** [October 31, 2019, 7:08am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/7 "2019-10-31T07:08:57Z")

</div>

I wasn’t able to see the linked issue. In any case, i wasn’t able to use relative paths either. Not sure if i did it wrong, but i checked with a Codefresh staff member and engineering is adding the enhancement for a freestyle step to be able to access volumes in service containers.

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [October 31, 2019, 3:26pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/8 "2019-10-31T15:26:28Z")

</div>

Our engineering team added automounting on service containers in the setup block.

```
version: '1.0'
steps:
  main_clone:
    title: Cloning main repository...
    type: git-clone
    repo: 'codefreshdemo/cf-example-unit-test'
    revision: 'master'
    git: github
  hello_world_step:
    title: free style step
    image: node:11
    commands:
      - ls -l /codefresh/volume/
      - cat /codefresh/volume/test.txt
    services:
      composition:
        my_custom_service:
          image: 'alpine:latest'  
      setup:
        image: 'alpine:latest'
        commands:
          - "ls -l /codefresh/volume"
          - "echo 'from service' > /codefresh/volume/test.txt"

```

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [October 31, 2019, 3:27pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/9 "2019-10-31T15:27:27Z")

</div>

You can also mount the volume yourself in the service container itself, but I don’t recommend this. I think the setup block is better

```
version: '1.0'
steps:
  main_clone:
    title: Cloning main repository...
    type: git-clone
    repo: 'codefreshdemo/cf-example-unit-test'
    revision: 'master'
    git: github
  hello_world_step:
    title: free style step
    image: node:11
    commands:
      - ls -l /codefresh/volume/
      - cat /codefresh/volume/test.txt
    services:
      composition:
        my_custom_service:
          image: 'alpine:latest'
          volumes:
            - ${{CF_VOLUME_NAME}}:/codefresh/volume
          command: 'ls -l /codefresh/volume'
      setup:
        image: 'alpine:latest'
        commands:
          - "echo 'from service' > /codefresh/volume/test.txt"

```

---

<div class="post-metadata">

**Author:** ![evanx9](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/evanx9/32/156_2.png) [@evanx9](https://community.codefresh.io/u/evanx9)\
**Post date:** [November 4, 2019, 5:36pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/10 "2019-11-04T17:36:11Z")

</div>

> [@Kostis](#):
>
> volumes: - ${{CF\_VOLUME\_NAME}}:/codefresh/volume

Basically, this portion is always included then, from now on?

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [November 4, 2019, 7:58pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/11 "2019-11-04T19:58:22Z")

</div>

Yes, but only in the setup block (see first example I posted)

If you want it at the composition itself (not recommended) you still have to include it (second example I posted)

The idea is that in the setup block you preload the DB you use for testing or do some other init action, so you grab files from the shared Codefresh volume. And the volume is already there for you with no extra conf 🙂

---

<div class="post-metadata">

**Author:** ![rsung](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/rsung/32/244_2.png) [@rsung](https://community.codefresh.io/u/rsung)\
**Post date:** [April 20, 2020, 7:08pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/12 "2020-04-20T19:08:53Z")

</div>

@Kostis I’m still having challenges with shared volume. I’m getting the following error even though I’m following the documentation. The build spec snippet I’m using is below. Please advise.

**Error Message:**  
[SYSTEM]  
Message Failed to prepare composition: Run tests  
Caused by Cannot start composition with warnings [“Volume mapping is not supported, try use:  
/docker-entrypoint-initdb.d/mysql\_init.sql”]  
Documentation Link [Composition · Codefresh | Docs](https://codefresh.io/docs/docs/codefresh-yaml/steps/composition/)  
Pipeline executed successfully

**Build Spec**

```
  test:
    title: "Run tests"
    stage: Test
    type: composition
    fail_fast: true
    composition:
      version: "3"
      services:
        # Cache
        exos-redis:
          image: redis:3.2.8
          container_name: "redis"
          expose:
            - "6379"
          healthcheck:
            test: ["CMD", "redis-cli", "-h", "localhost", "ping"]
            interval: 10s
            timeout: 10s
            retries: 5
        # DB
        members-mysql:
          image: mysql/mysql-server:8.0.15
          env_file: .env
          ports:
            - 3306
          environment:
            MYSQL_ROOT_PASSWORD:abc
          volumes:
            - '${{CF_VOLUME_NAME}}/members/etc/docker/mysql/mysql_init.sql:/docker-entrypoint-initdb.d/mysql_init.sql'
          healthcheck:
            test: ["CMD", "curl", "-f", "http://localhost:3306"]
            interval: 10s
            timeout: 10s
            retries: 5
          command: --default-authentication-plugin=mysql_native_password

    composition_candidates:
      app:
        image: ${{build_members_test_image}}
        command: infrastructure/codefresh/test/test.sh
        env_file:
          - infrastructure/codefresh/test/test.env

```

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [April 20, 2020, 9:10pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/13 "2020-04-20T21:10:34Z")

</div>

Hey. It is exactly as this error message states. We don’t support volume directives with compositions.

Basically even though we still support compositions, we have since introduced service containers that are much better [Service Containers · Codefresh | Docs](https://codefresh.io/docs/docs/codefresh-yaml/service-containers/)

One of the advantages of service containers, is that you don’t have to mess with volumes any more. The main volume of the pipeline is already mounted to all services so you can freely access yours files from any service.

I looked at your example and you are still using the old composition syntax instead of the new one (service containers)

Here are also some full examples

- [Populate a database with existing data · Codefresh | Docs](https://codefresh.io/docs/docs/yaml-examples/examples/populate-a-database-with-existing-data/)
- [Integration Tests with MySQL · Codefresh | Docs](https://codefresh.io/docs/docs/yaml-examples/examples/integration-tests-with-mysql/)

---

<div class="post-metadata">

**Author:** ![qbiqing](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/qbiqing/32/383_2.png) [@qbiqing](https://community.codefresh.io/u/qbiqing)\
**Post date:** [August 2, 2021, 5:57am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/14 "2021-08-02T05:57:35Z")

</div>

> We don’t support volume directives with compositions.

I want to check that means the instructions from this page on how to access the Docker daemon in Codefresh is completely void? [https://support.codefresh.io/hc/en-us/articles/360017901040-How-to-Access-the-Docker-Daemon-in-a-Codefresh-build](https://support.codefresh.io/hc/en-us/articles/360017901040-How-to-Access-the-Docker-Daemon-in-a-Codefresh-build) since the stated preferred way is to use the composition step, and mount the Docker socket `/var/run/docker.sock:/var/run/docker.sock`.

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [August 2, 2021, 10:09am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/15 "2021-08-02T10:09:38Z")

</div>

Hello

The support page that you reference is newer than the docs.

However, I cannot guarantee that it will work for you, because over the last months we have locked down several aspects of Codefresh, because of Cryptominer abuse.

I suggest you try the mounting of the socket in a composition and if it doesn’t work, please open a ticket with us so that we can investigate.

May I ask which tool you want to use in your Codefresh pipeline that required direct socket access to the docker daemon?

---

<div class="post-metadata">

**Author:** ![tmgodinho](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/tmgodinho/32/453_2.png) [@tmgodinho](https://community.codefresh.io/u/tmgodinho)\
**Post date:** [January 5, 2022, 3:14pm UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/16 "2022-01-05T15:14:29Z")

</div>

Hi @qbiqing & @Kostis,

Did you eventually manage to get the test-containers up and running in code-fresh??  
I think I’m stuck trying to get the service volumes to mount properly.

---

<div class="post-metadata">

**Author:** ![qbiqing](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/qbiqing/32/383_2.png) [@qbiqing](https://community.codefresh.io/u/qbiqing)\
**Post date:** [January 6, 2022, 9:29am UTC](https://community.codefresh.io/t/shared-volumes-in-freestyle-composition/156/17 "2022-01-06T09:29:23Z")

</div>

hi @tmgodinho, I opened a separate issue here: [Mounting Docker socket in composition step](https://community.codefresh.io/t/mounting-docker-socket-in-composition-step/615)

I was trying to mount a docker socket in composition and it was not allowed
