Docker Community Forums

Share and learn in the Docker community.

Using Docker volumes

I am having a bit difficulties understanding the documentation. I’m trying to create a volume i can share among multiple images. Below example shows a docker compose file with 2 images using a single volume:

version: "3.9"
services:
  test:
    image: test
    build:
      context: .
      dockerfile: Test
    volumes: 
      - mytest:/opt
  test2:
    image: test
    build:
      context: .
      dockerfile: Testshare
    volumes: 
      - mytest:/opt

volumes:
  mytest:

I can see that the volume has been created with compose up. I’m not sure at this point whether the volume is used by the image - my changes are not persistent.

Volumes defined this way for the containers not the images. What exactly do you want to achieve?