How to use named volume in docker-compose.yml

Conclusion

It's a very rough explanation because I don't understand much yet, You can use the named volume by writing the docker-compose.yml file as shown below.

docer-compose.yml


version: '3'

services:
    web:
      build: .
      
      ...
      volumes:
          - .:/myapp      
          - gem_data:/usr/local/bundle
          #here
      ...
volumes:
  gem_data:
  #This is important.

- gem_data:/usr/local/bundle This is the named path.

At the bottom of the above code,

volumes:
    gem_data:

Without this ERROR: Named volume "gem_data:/usr/local/bundle" is used in service "gem_data:" but no declaration was found in the volumes section. I get an error and it seems that I can not specify it unless I use a relative path or an absolute path.

It seems that it is basically better to use a named path than to use a relative path.

reference

Mounting MySQL data on Docker to the host directory with Volume will be troublesome around permissions https://qiita.com/ysd_marrrr/items/e8a50c43cff87951385c

Recommended Posts

How to use named volume in docker-compose.yml
How to use Lombok in Spring
How to use InjectorHolder in OpenAM
How to use classes in Java?
Multilingual Locale in Java How to use Locale
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How to use environment variables in RubyOnRails
Understand in 5 minutes !! How to use Docker
How to use credentials.yml.enc introduced in Rails 5.2
How to execute multiple commands in docker-compose.yml
How to use ExpandableListView in Android Studio
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
How to use Dozer.mapper
How to use Gradle
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use Map
[Rails] How to use select boxes in Ransack
How to use "sign_in" in integration test (RSpec)
How to use JQuery in js.erb of Rails6
[Rails] How to use PostgreSQL in Vagrant environment
[Java] How to use Map
[Ruby] How to use standard output in conditional branching
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
[Rails] How to use enum
How to use java Optional
How to use JUnit (beginner)
How to use Ruby return
How to use Z3 library in Scala with Eclipse
[Rails] How to use enum
How to use @Builder (Lombok)
[Swift] How to use UserDefaults
How to use java class
Understand how to use Swift's JSON Decoder in 3 minutes
How to use Swift UIScrollView
How to use Big Decimal
[Java] How to use Optional ②
[Java] How to use removeAll ()
How to use String [] args
[Java] How to use string.format
How to use rails join