title: Generating files in Docker vs. Docker Compose
body: <p>I am learning Docker and have a little confusion that I would greatly appreciate some advice on.</p>
  <p>When creating a new rails application. Following the guidelines of Docker's tutorial <a href="https://docs.docker.com/samples/rails/" rel="nofollow noreferrer">Quickstart: Compose &amp; Rails</a>. They're steps are as follows.</p>
  <ol>
  <li>Create Dockerfile &amp; Entrypoint</li>
  <li>Create Gemfile with source and rails gem listed.</li>
  <li>Create an empty Gemfile.lock</li>
  <li>Create a docker-compose.yml and name services.</li>
  <li>Generate a new rails app using docker-compose run.</li>
  </ol>
  <p>The rails new command.</p>
  <pre><code>docker-compose run --no-deps web rails new . --force -d mysql
  </code></pre>
  <p>This is my simple Dockerfile:</p>
  <pre><code>FROM ruby:3.1.1-alpine3.15
  
  RUN apk update -q
  RUN apk add bash yarn git build-base nodejs mariadb-dev tzdata
  
  WORKDIR /app
  
  COPY Gemfile /app/Gemfile
  COPY Gemfile.lock /app/Gemfile.lock
  
  COPY package.json /app/package.json
  COPY yarn.lock /app/yarn.lock
  
  RUN gem install bundler
  RUN gem update bundler
  RUN bundle install
  
  COPY entrypoint.sh /usr/bin
  RUN chmod +x /usr/bin/entrypoint.sh
  ENTRYPOINT [&quot;entrypoint.sh&quot;]
  
  EXPOSE 3000
  </code></pre>
  <p>This is my docker-compose.yml:</p>
  <pre><code>version: &quot;3.9&quot;
  services:
    web:
      build: .
      command: bash -c &quot;rm -f tmp/pids/server.pid &amp;&amp; bundle exec rails s -p 3000 -b '0.0.0.0'&quot;
      volumes:
        - .:/app
      ports:
        - &quot;3000:3000&quot;
  </code></pre>
  <p>As you can see I only have one service listed in my docker-compose.yml, because I do not want any other services or containers.</p>
  <p>Everything works fine when I use the command docker-compose run rails new ... it generates a new rails app and persists the files to my local source folder. So I can open and edit the files to develop the application. Perfect.</p>
  <p>But when I try and generate a new Rails app without using docker-compose.yml and only the Dockerfile. The generated files are not persisted in my local source folder, only on the container. I can only assume because I am forced to build the image before running it in a container to generate the new rails app.</p>
  <p>When using without docker-compose.yml. I have to build the image first.</p>
  <pre><code>docker build -t image_name .
  </code></pre>
  <p>Then I can run the container and generate the rails app.</p>
  <pre><code>docker run image_name rails new . --force -d mysql
  </code></pre>
  <p>Obviously, this doesn't persit the new files in my local source folder.</p>
  <p><strong>How can I generate a new Rails app with just my Dockerfile without docker compose and still have the newly generated files persist in my local source folder?</strong></p>
  <p>I must be missing something, but I've done a lot of research and can't find an answer.</p>