<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="174940" data-post-id="174940">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Exadra37" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Exadra37/120/9183_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Exadra37
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Share your Dockerfile and docker compose so that we can try to help you, because I use Docker for all my development stuff, including to run the Android Studio editor, that’s a very complex and heavy tool, and things just works, provided you have the correct setup and Operating System <img src="https://forum.elixirforum.com/images/emoji/apple/wink.png?v=15" title=":wink:" class="emoji" alt=":wink:" loading="lazy" width="20" height="20"></p>
<p>I use an Elixir Docker Stack with a lot of bash helpers that makes Elixir development a breeze and a joy, and I also run the editor from inside another docker container.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="174940" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-174940" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="174940"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="175046" data-post-id="175046">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JackMaarek" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JackMaarek/120/18793_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JackMaarek
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>With pleasure !</p>
<p>Here is the new project directory:</p>
<p></p><div class="lightbox-wrapper"><a class="lightbox" href="https://forum.elixirforum.com/uploads/default/original/3X/e/2/e28d4385aa44ea56b6c91bb798359117bdde2b3f.png" data-download-href="https://forum.elixirforum.com/uploads/default/e28d4385aa44ea56b6c91bb798359117bdde2b3f" title="Screenshot 2020-05-12 at 15.31.10" rel="nofollow"><img src="https://forum.elixirforum.com/uploads/default/original/3X/e/2/e28d4385aa44ea56b6c91bb798359117bdde2b3f.png" alt="Screenshot 2020-05-12 at 15.31.10" data-base62-sha1="wkaz02N8CfzsvlrrV7IiIj2aPFl" width="504" height="542"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2020-05-12 at 15.31.10</span><span class="informations">504×542 19.6 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><p></p>
<p>The Dockerfile :</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">FROM elixir:latest


RUN mix local.hex --force &amp;&amp;\
    mix local.rebar --force &amp;&amp;\
    #This part could be removed as we do not need to install phoenix dependencies.
    mix archive.install hex phx_new 1.4.16 --force

RUN apt-get update &amp;&amp; \
  ## install inotify-tool for phoenix hot reload
  apt-get install -y inotify-tools &amp;&amp; \
  # install nodejs and npm on globaly
  curl -sL https://deb.nodesource.com/setup_14.x | bash - &amp;&amp; \
   apt-get install -y -q nodejs &amp;&amp; \
  # Install postgres client
  apt-get install -y postgresql-client &amp;&amp; \
  # Clear apt cache
   rm -rf /var/lib/apt/lists/*

WORKDIR /phoenix

COPY . /phoenix

EXPOSE 4000
</code></pre>
<p>The docker-compose file:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">version: '3.7'

services:
  db:
    image: postgres:9.6
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGDATA: /var/lib/postgresql/data/pgdata
    restart: always
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
  phoenix:
    build: .
    volumes:
      - .docker/phoenix/phoenix-setup.sh:/phoenix-setup.sh
    command: ../phoenix-setup.sh
    environment:
      PGUSER: postgres
      PGPASSWORD: postgres
      PGDATABASE: portfolio
      PGPORT: 5432
      PGHOST: db
    ports:
      - "4000:4000"
    depends_on:
      - db
volumes:
  pgdata:
</code></pre>
<p>And .dockerignore:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">deps
_build
assets/node_modules
test
</code></pre>
<p>If you have any suggestion/reviews I will love to hear them.</p>
<p>Thanks a lot !</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175046" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-175046" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175046"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="175052" data-post-id="175052">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Exadra37" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Exadra37/120/9183_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Exadra37
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just a quick question… Do you run your project code from within your editor, be it for running tests or anything else, like to open a iex session?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175052" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-175052" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175052"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="175059" data-post-id="175059">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JackMaarek" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JackMaarek/120/18793_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JackMaarek
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Generaly I just use my terminal not the one from the editor. For now i’m not working with docker containers on dev env as I need to restart them on each changes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175059" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-175059" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175059"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="175063" data-post-id="175063">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Exadra37" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Exadra37/120/9183_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Exadra37
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>So just remove from your Dockerfile:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">COPY . /phoenix

EXPOSE 4000
</code></pre>
<p>Add this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">WORKDIR /app
</code></pre>
<p>and fix your docker compose volume to:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">- $PWD:/app
</code></pre>
<p>But his is running as root, and that is not good from a security point of view.</p>
<p>With this changes you don’t need to rebuild your image each time you change files in the host.</p>
<p>Just <a href="https://gitlab.com/exadra37-bash/docker/bash-scripts-for-docker-builds/-/blob/bbc8647cc491b49206631acdc18b087126f00aaa/scripts/debian/install/inotify-tools.sh" rel="noopener nofollow ugc">add inotify tools</a> to the container and host OS and change the max number of files he can watch, and you are good to go.</p>
<pre data-code-wrap="bash"><code class="lang-bash">#!/bin/sh

set -eu

Main()
{
    apt install -y -q --no-install-recommends \
        procps \
        inotify-tools

    printf "fs.inotify.max_user_watches=524288\n" &gt; /etc/sysctl.d/01-inotify.conf
}

Main
</code></pre>
<p>I use this for years without any problems.</p>
<p>I am working on an <a href="https://gitlab.com/exadra37-docker/elixir/elixir-docker-stack/-/tree/dev-new-approach" rel="noopener nofollow ugc">Elixir Docker Stack</a> that just makes everything a breeze, but not yet ready for others to try because the base image is not yet released in Docker Hub, therefore you cannot try it in your computer.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175063" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-175063" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175063"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="175077" data-post-id="175077">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="JackMaarek" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/JackMaarek/120/18793_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  JackMaarek
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well this is a nice fix but I don’t think that it resolve the shadowing issues of deps folder in the container, by using volumes it will pull all the local files into the container and shadow the stuff in the container… I just tried it and I got an error while loading Bcrypt on a sign-in method for example.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175077" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-175077" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175077"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="175080" data-post-id="175080">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Exadra37" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Exadra37/120/9183_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Exadra37
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="JackMaarek" data-post="17" data-topic="30417">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jackmaarek/48/18793_2.png" class="avatar"> JackMaarek:</div>
<blockquote>
<p>Well this is a nice fix but I don’t think that it resolve the shadowing issues of deps folder in the container, by using volumes it will pull all the local files into the container and shadow the stuff in the container…</p>
</blockquote>
</aside>
<p>The shadowing issue is only an issue if you run <code>mix deps.get</code> and <code>mix compile</code> in both the host and the container, otherwise is a non issue. If you run in both than you just need to map each folder in your root project and leave out the <code>deps</code>,  <code>_build</code> and I think the <code>assets/node_modules</code> folders.</p>
<aside class="quote no-group" data-username="JackMaarek" data-post="17" data-topic="30417">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jackmaarek/48/18793_2.png" class="avatar"> JackMaarek:</div>
<blockquote>
<p>I just tried it and I got an error while loading Bcrypt on a sign-in method for example.</p>
</blockquote>
</aside>
<p>This is a completely different issue, and is nothing related with shadowing, instead it means you are missing the OS dependencies to build bccrypt in the container or if you are running mix commands in both the host and in the container, then it may cause issues, because bcrypt was compiled for a different target, but without seeing the exact error is hard to say.</p>
<p>To resume if you don’t run mix commands in both the container and host, shadowing is a <strong>non issue</strong>.</p>
<h2><a name="p-175080-docker-stack-1" class="anchor" href="#p-175080-docker-stack-1" aria-label="Heading link" rel="nofollow"></a>Docker Stack</h2>
<h3><a name="p-175080-dockerfile-2" class="anchor" href="#p-175080-dockerfile-2" aria-label="Heading link" rel="nofollow"></a>Dockerfile</h3>
<p>The Dockerfile now as non root user with the id <code>1000</code>. Please read the comments in the Dockerfile to see if you need to customize this id for your computer.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">ARG TAG=latest

FROM elixir:${TAG}

ARG PHOENIX_VERSION=1.4.16

RUN apt-get update &amp;&amp; \

  ## install inotify-tool for phoenix hot reload
  apt-get install -y inotify-tools &amp;&amp; \
  # DO THE SAME IN YOUR HOST MACHINE
  printf "fs.inotify.max_user_watches=524288\n" &gt; /etc/sysctl.d/01-inotify.conf &amp;&amp; \

  # install nodejs and npm on globaly
  curl -sL https://deb.nodesource.com/setup_14.x | bash - &amp;&amp; \
  apt-get install -y -q nodejs &amp;&amp; \

  # Add the user `developer` with id `1000`. Adjust `1000` to match the user in
  #  your host in order to avoid permissions issues between container and host.
  # To check user id in host, just run: `id -u`
  useradd -m -u 1000 -s /bin/bash developer &amp;&amp; \
  su developer -c 'mkdir -p /home/developer/phoenix' &amp;&amp; \

  # Install postgres client
  apt-get install -y postgresql-client &amp;&amp; \
  # Clear apt cache
  rm -rf /var/lib/apt/lists/*

USER developer

RUN mix local.hex --force &amp;&amp;\
    mix local.rebar --force &amp;&amp;\
    mix archive.install hex phx_new ${PHOENIX_VERSION} --force

WORKDIR /home/developer/phoenix

CMD ["bash"]
</code></pre>
<p>You can now build any combination of Elixir and Phoenix version:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">docker build --build-arg "TAG=1.10" --build-arg "PHOENIX_VERSION=1.5.1" -t phoenix:1.10_1.5.1 .
</code></pre>
<h3><a name="p-175080-docker-compose-3" class="anchor" href="#p-175080-docker-compose-3" aria-label="Heading link" rel="nofollow"></a>Docker Compose</h3>
<p>I don’t have Elixir installed in my host, therefore I cannot test this docker compose file, but if I have not missed anything it will allow you to run mix commands from the host and container without causing issues:</p>
<pre data-code-wrap="yml"><code class="lang-yml"># DONT USER VERSION £ UNLESS YOUR ARE USING DOCKER SWARM TO RUN THE CONTIANERS
version: '2.3'

services:
  db:
    image: postgres:9.6
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGDATA: /var/lib/postgresql/data/pgdata
    restart: always
    volumes:
      - ./pgdata:/var/lib/postgresql/data
    ports:
      # IF POSTGRES IS ONLY USED BY THE PHOENIX SERVICE THEN YOU CAN REMOVE THIS PORT MAP
      # This is listening to requests coming from outside your computer:
      #- "5432:5432"
      # Localhost only
      - "127.0.0.1:5432:5432"
  phoenix:
    build: .
    volumes:
      - $PWD/assets/css:/home/developer/phoenix/assets/css
      - $PWD/assets/js:/home/developer/phoenix/assets/js
      - $PWD/assets/static:/home/developer/phoenix/assets/static
      - $PWD/assets/package.json:/home/developer/phoenix/assets/package.json
      - $PWD/assets/package-lock.json:/home/developer/phoenix/assets/package-lock.json
      - $PWD/assets/webpack.config.js:/home/developer/phoenix/assets/webpack.config.js
      - $PWD:/home/developer/phoenix/config
      - $PWD:/home/developer/phoenix/lib
      - $PWD:/home/developer/phoenix/priv
      - $PWD/mix.exs:/home/developer/phoenix/mix.exs
      - $PWD/mix.lock:/home/developer/phoenix/mix.lock
      - $PWD/.formatter.exs:/home/developer/phoenix/.formatter.exs
    
    # DONT KNOW WHAT IS DOING BUT PROBABLY YOU WANT TO ADJUST IT FOR THE NEW STACK.
    #command: ../phoenix-setup.sh
    command: mix phx.server
    environment:
      PGUSER: postgres
      PGPASSWORD: postgres
      PGDATABASE: portfolio
      PGPORT: 5432
      PGHOST: db
    ports:
      # Only visible to localhost, otherwise will be 0.0.0.0, meaning it will listen to requests coming from outsiide.
      - "127.0.0.1:4000:4000"
    depends_on:
      - db
volumes:
  pgdata:

</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="175080" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-solid-docker-compose-recipes/30417/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-175080" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="175080"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>