Configure docker volumes to share data across host and containers












0















I am stuck trying to configure docker volumes to share files between my host and make able in my container to use this files. let me explain.



I have a rails docker app with puma as a web server, I want to make able to puma to view and use the ssl .key and .crt files, so for this project also I am using docker-compose in "production mode", but I do not know how to make this work.



My setup is this:




  • Ubuntu 18.04 server host for production has the ssl files inside /home/ubuntu/my_app_keys, the containers are also in my host.


/home/ubuntu/docker-compose.yml



version: '3'

services:
postgres:
image: postgres:10.5
environment:
POSTGRES_DB: my_app_production
env_file:
-~/production.env

redis:
image: redis:4.0.11

web:
image: my_app:latest
command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' -e production
ports:
- '3000:3000'
volumes:
- /home/ubuntu/my_app_keys
depends_on:
- postgres
- redis
env_file:
- ~/production.env
restart: always

sidekiq:
image: my_app_sidekiq:latest
command: bundle exec sidekiq -C config/sidekiq.yml
depends_on:
- postgres
- redis
env_file:
- ~/production.env
restart: always


so, as you can see: command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' is looking for ssl files in /home/ubuntu/my_app_keys, when I execute docker-compose up puma can not find the ssl files and exits with:



/usr/local/bundle/gems/puma-3.9.1/lib/puma/minissl.rb:180:in `key=': No such key file '/home/ubuntu/my_app_keys/server.key' (ArgumentError)


I think is because key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt are pointing in the container context but I have the cert and key in my host context



so, I include in docker compose volume in order to bind-mount the files:



volumes:
- /home/ubuntu/my_app_keys


but without luck, same error.



In the container context my app lives in /var/www/my_app directory, so I tried to specify an absolute path (for some reason I imagined that it was because the ssl files were not in the same directory where my app lived could not be shared), so I add as compose-file docs say:



volumes:
- /home/ubuntu/my_app_keys:/var/www/my_app


and change in compose file:



command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=server.key&cert=server.crt' -e


when I execute the compose up my web service exit with error:



web | Could not locate Gemfile or .bundle/ directory


only way that web service run is (but no ssl files exist):



volumes:
- /home/ubuntu/my_app_keys


so, I do not know what to do now. any help?










share|improve this question



























    0















    I am stuck trying to configure docker volumes to share files between my host and make able in my container to use this files. let me explain.



    I have a rails docker app with puma as a web server, I want to make able to puma to view and use the ssl .key and .crt files, so for this project also I am using docker-compose in "production mode", but I do not know how to make this work.



    My setup is this:




    • Ubuntu 18.04 server host for production has the ssl files inside /home/ubuntu/my_app_keys, the containers are also in my host.


    /home/ubuntu/docker-compose.yml



    version: '3'

    services:
    postgres:
    image: postgres:10.5
    environment:
    POSTGRES_DB: my_app_production
    env_file:
    -~/production.env

    redis:
    image: redis:4.0.11

    web:
    image: my_app:latest
    command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' -e production
    ports:
    - '3000:3000'
    volumes:
    - /home/ubuntu/my_app_keys
    depends_on:
    - postgres
    - redis
    env_file:
    - ~/production.env
    restart: always

    sidekiq:
    image: my_app_sidekiq:latest
    command: bundle exec sidekiq -C config/sidekiq.yml
    depends_on:
    - postgres
    - redis
    env_file:
    - ~/production.env
    restart: always


    so, as you can see: command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' is looking for ssl files in /home/ubuntu/my_app_keys, when I execute docker-compose up puma can not find the ssl files and exits with:



    /usr/local/bundle/gems/puma-3.9.1/lib/puma/minissl.rb:180:in `key=': No such key file '/home/ubuntu/my_app_keys/server.key' (ArgumentError)


    I think is because key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt are pointing in the container context but I have the cert and key in my host context



    so, I include in docker compose volume in order to bind-mount the files:



    volumes:
    - /home/ubuntu/my_app_keys


    but without luck, same error.



    In the container context my app lives in /var/www/my_app directory, so I tried to specify an absolute path (for some reason I imagined that it was because the ssl files were not in the same directory where my app lived could not be shared), so I add as compose-file docs say:



    volumes:
    - /home/ubuntu/my_app_keys:/var/www/my_app


    and change in compose file:



    command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=server.key&cert=server.crt' -e


    when I execute the compose up my web service exit with error:



    web | Could not locate Gemfile or .bundle/ directory


    only way that web service run is (but no ssl files exist):



    volumes:
    - /home/ubuntu/my_app_keys


    so, I do not know what to do now. any help?










    share|improve this question

























      0












      0








      0








      I am stuck trying to configure docker volumes to share files between my host and make able in my container to use this files. let me explain.



      I have a rails docker app with puma as a web server, I want to make able to puma to view and use the ssl .key and .crt files, so for this project also I am using docker-compose in "production mode", but I do not know how to make this work.



      My setup is this:




      • Ubuntu 18.04 server host for production has the ssl files inside /home/ubuntu/my_app_keys, the containers are also in my host.


      /home/ubuntu/docker-compose.yml



      version: '3'

      services:
      postgres:
      image: postgres:10.5
      environment:
      POSTGRES_DB: my_app_production
      env_file:
      -~/production.env

      redis:
      image: redis:4.0.11

      web:
      image: my_app:latest
      command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' -e production
      ports:
      - '3000:3000'
      volumes:
      - /home/ubuntu/my_app_keys
      depends_on:
      - postgres
      - redis
      env_file:
      - ~/production.env
      restart: always

      sidekiq:
      image: my_app_sidekiq:latest
      command: bundle exec sidekiq -C config/sidekiq.yml
      depends_on:
      - postgres
      - redis
      env_file:
      - ~/production.env
      restart: always


      so, as you can see: command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' is looking for ssl files in /home/ubuntu/my_app_keys, when I execute docker-compose up puma can not find the ssl files and exits with:



      /usr/local/bundle/gems/puma-3.9.1/lib/puma/minissl.rb:180:in `key=': No such key file '/home/ubuntu/my_app_keys/server.key' (ArgumentError)


      I think is because key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt are pointing in the container context but I have the cert and key in my host context



      so, I include in docker compose volume in order to bind-mount the files:



      volumes:
      - /home/ubuntu/my_app_keys


      but without luck, same error.



      In the container context my app lives in /var/www/my_app directory, so I tried to specify an absolute path (for some reason I imagined that it was because the ssl files were not in the same directory where my app lived could not be shared), so I add as compose-file docs say:



      volumes:
      - /home/ubuntu/my_app_keys:/var/www/my_app


      and change in compose file:



      command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=server.key&cert=server.crt' -e


      when I execute the compose up my web service exit with error:



      web | Could not locate Gemfile or .bundle/ directory


      only way that web service run is (but no ssl files exist):



      volumes:
      - /home/ubuntu/my_app_keys


      so, I do not know what to do now. any help?










      share|improve this question














      I am stuck trying to configure docker volumes to share files between my host and make able in my container to use this files. let me explain.



      I have a rails docker app with puma as a web server, I want to make able to puma to view and use the ssl .key and .crt files, so for this project also I am using docker-compose in "production mode", but I do not know how to make this work.



      My setup is this:




      • Ubuntu 18.04 server host for production has the ssl files inside /home/ubuntu/my_app_keys, the containers are also in my host.


      /home/ubuntu/docker-compose.yml



      version: '3'

      services:
      postgres:
      image: postgres:10.5
      environment:
      POSTGRES_DB: my_app_production
      env_file:
      -~/production.env

      redis:
      image: redis:4.0.11

      web:
      image: my_app:latest
      command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' -e production
      ports:
      - '3000:3000'
      volumes:
      - /home/ubuntu/my_app_keys
      depends_on:
      - postgres
      - redis
      env_file:
      - ~/production.env
      restart: always

      sidekiq:
      image: my_app_sidekiq:latest
      command: bundle exec sidekiq -C config/sidekiq.yml
      depends_on:
      - postgres
      - redis
      env_file:
      - ~/production.env
      restart: always


      so, as you can see: command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt' is looking for ssl files in /home/ubuntu/my_app_keys, when I execute docker-compose up puma can not find the ssl files and exits with:



      /usr/local/bundle/gems/puma-3.9.1/lib/puma/minissl.rb:180:in `key=': No such key file '/home/ubuntu/my_app_keys/server.key' (ArgumentError)


      I think is because key=/home/ubuntu/my_app_keys/server.key&cert=/home/ubuntu/my_app_keys/server.crt are pointing in the container context but I have the cert and key in my host context



      so, I include in docker compose volume in order to bind-mount the files:



      volumes:
      - /home/ubuntu/my_app_keys


      but without luck, same error.



      In the container context my app lives in /var/www/my_app directory, so I tried to specify an absolute path (for some reason I imagined that it was because the ssl files were not in the same directory where my app lived could not be shared), so I add as compose-file docs say:



      volumes:
      - /home/ubuntu/my_app_keys:/var/www/my_app


      and change in compose file:



      command: bundle exec rails server -p 3000 -b 'ssl://127.0.0.1:3000?key=server.key&cert=server.crt' -e


      when I execute the compose up my web service exit with error:



      web | Could not locate Gemfile or .bundle/ directory


      only way that web service run is (but no ssl files exist):



      volumes:
      - /home/ubuntu/my_app_keys


      so, I do not know what to do now. any help?







      ruby-on-rails docker ssl docker-compose






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 22:11









      Carlos GómezCarlos Gómez

      649




      649
























          1 Answer
          1






          active

          oldest

          votes


















          0














          When your Docker Compose YAML file says:



          volumes:
          - /home/ubuntu/my_app_keys


          It means, "make /home/ubuntu/my_app_keys in container space persist across restarts of the container; it will start off empty unless the Dockerfile did something special; it's not connected to any specific host content".



          When you say:



          volumes:
          - /home/ubuntu/my_app_keys:/var/www/my_app


          It means, "totally replace the contents of /var/www/my_app in container space with the contents of /home/ubuntu/my_app_keys on the host". (The path names in host and container space don't need to be the same.)



          As a bonus question, when you say:



          rails server -b 'ssl://127.0.0.1:3000?...'


          It means, "only listen for inbound connections on port 3000 initiated from within this Docker container; don't accept any connections from outside the container at all, whether from the same physical host, other containers, or elsewhere."






          share|improve this answer
























          • I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

            – Carlos Gómez
            Nov 23 '18 at 17:15











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438521%2fconfigure-docker-volumes-to-share-data-across-host-and-containers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          When your Docker Compose YAML file says:



          volumes:
          - /home/ubuntu/my_app_keys


          It means, "make /home/ubuntu/my_app_keys in container space persist across restarts of the container; it will start off empty unless the Dockerfile did something special; it's not connected to any specific host content".



          When you say:



          volumes:
          - /home/ubuntu/my_app_keys:/var/www/my_app


          It means, "totally replace the contents of /var/www/my_app in container space with the contents of /home/ubuntu/my_app_keys on the host". (The path names in host and container space don't need to be the same.)



          As a bonus question, when you say:



          rails server -b 'ssl://127.0.0.1:3000?...'


          It means, "only listen for inbound connections on port 3000 initiated from within this Docker container; don't accept any connections from outside the container at all, whether from the same physical host, other containers, or elsewhere."






          share|improve this answer
























          • I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

            – Carlos Gómez
            Nov 23 '18 at 17:15
















          0














          When your Docker Compose YAML file says:



          volumes:
          - /home/ubuntu/my_app_keys


          It means, "make /home/ubuntu/my_app_keys in container space persist across restarts of the container; it will start off empty unless the Dockerfile did something special; it's not connected to any specific host content".



          When you say:



          volumes:
          - /home/ubuntu/my_app_keys:/var/www/my_app


          It means, "totally replace the contents of /var/www/my_app in container space with the contents of /home/ubuntu/my_app_keys on the host". (The path names in host and container space don't need to be the same.)



          As a bonus question, when you say:



          rails server -b 'ssl://127.0.0.1:3000?...'


          It means, "only listen for inbound connections on port 3000 initiated from within this Docker container; don't accept any connections from outside the container at all, whether from the same physical host, other containers, or elsewhere."






          share|improve this answer
























          • I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

            – Carlos Gómez
            Nov 23 '18 at 17:15














          0












          0








          0







          When your Docker Compose YAML file says:



          volumes:
          - /home/ubuntu/my_app_keys


          It means, "make /home/ubuntu/my_app_keys in container space persist across restarts of the container; it will start off empty unless the Dockerfile did something special; it's not connected to any specific host content".



          When you say:



          volumes:
          - /home/ubuntu/my_app_keys:/var/www/my_app


          It means, "totally replace the contents of /var/www/my_app in container space with the contents of /home/ubuntu/my_app_keys on the host". (The path names in host and container space don't need to be the same.)



          As a bonus question, when you say:



          rails server -b 'ssl://127.0.0.1:3000?...'


          It means, "only listen for inbound connections on port 3000 initiated from within this Docker container; don't accept any connections from outside the container at all, whether from the same physical host, other containers, or elsewhere."






          share|improve this answer













          When your Docker Compose YAML file says:



          volumes:
          - /home/ubuntu/my_app_keys


          It means, "make /home/ubuntu/my_app_keys in container space persist across restarts of the container; it will start off empty unless the Dockerfile did something special; it's not connected to any specific host content".



          When you say:



          volumes:
          - /home/ubuntu/my_app_keys:/var/www/my_app


          It means, "totally replace the contents of /var/www/my_app in container space with the contents of /home/ubuntu/my_app_keys on the host". (The path names in host and container space don't need to be the same.)



          As a bonus question, when you say:



          rails server -b 'ssl://127.0.0.1:3000?...'


          It means, "only listen for inbound connections on port 3000 initiated from within this Docker container; don't accept any connections from outside the container at all, whether from the same physical host, other containers, or elsewhere."







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 2:49









          David MazeDavid Maze

          12.4k31225




          12.4k31225













          • I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

            – Carlos Gómez
            Nov 23 '18 at 17:15



















          • I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

            – Carlos Gómez
            Nov 23 '18 at 17:15

















          I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

          – Carlos Gómez
          Nov 23 '18 at 17:15





          I see, thank you for the explanation, I changed volumes to /home/ubuntu/my_app_keys:/var/www/my_app/ssl and also changed rails server -b 'ssl://0.0.0.0:3000?...' as puma server documentation says 0.0.0.0 default. but no luck, I am unable to see .key and .crt files in container in path .../my_app/ssl

          – Carlos Gómez
          Nov 23 '18 at 17:15


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53438521%2fconfigure-docker-volumes-to-share-data-across-host-and-containers%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'