title: Dockerfile: Copy dependencies builded in slim base image to alpine
body: <p>I have a Dockerfile:</p>
  <pre><code>FROM python:3.8.7-slim AS builder
  
  ENV POETRY_VIRTUALENVS_CREATE=false
  
  WORKDIR /code
  
  RUN apt-get update
  RUN apt-get install -y --no-install-recommends libsasl2-dev libldap2-dev
  RUN apt-get install -y --no-install-recommends gcc
  RUN apt-get install -y --no-install-recommends graphviz-dev
  COPY poetry.lock pyproject.toml ./
  RUN pip install --upgrade pip &amp;&amp; pip install --no-cache-dir poetry
  RUN poetry install
  
  
  FROM python:3.8.7-alpine3.13
  
  # to make pytest (celery etc) be available and executable one must copy their executables directly
  COPY --from=builder /usr/local/bin/celery /usr/local/bin/pytest /usr/local/bin/
  
  # IF OVERWRITE python IN /usr/local/bin ANYTHING DOES NOT WORK
  #COPY --from=builder /usr/local/bin /usr/local/bin
  
  COPY --from=builder /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
  
  WORKDIR /code
  COPY pythonapline .
  
  CMD [&quot;pytest&quot;]
  </code></pre>
  <p>Repo: <a href="https://github.com/albertalexandrov/slim-to-alpine/" rel="nofollow noreferrer">https://github.com/albertalexandrov/slim-to-alpine/</a></p>
  <p>As you can see there I am trying to build dependencies in python:3.8.7-slim base image and then copy all builded dependencies to python:3.8.7-alpine3.13.</p>
  <p>Build and run:</p>
  <pre><code>docker build -t slim2alpine .
  docker run slim2alpine
  </code></pre>
  <p>I found out that if I copy whole folder <strong>/usr/local/bin</strong> from <strong>builder</strong> to alpine then <strong>python</strong>, <strong>pytest</strong>, <strong>celery</strong> binaries become unavailable:</p>
  <p><a href="https://i.stack.imgur.com/wqipB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wqipB.png" alt="enter image description here" /></a></p>
  <p>But if I copy to another slim (not alpine) everything works.</p>
  <p>When I copy one by one binaries <code>COPY --from=builder /usr/local/bin/celery /usr/local/bin/pytest /usr/local/bin/</code> they work.</p>
  <p>What do I miss? Is that possible copy whole <strong>/usr/local/bin</strong> folder?</p>