# Understanding Docker Multi Stage Builds - Installing Python and Ruby in the Same Dockerfile

DevFeed: [Understanding Docker Multi Stage Builds - Installing Python and Ruby in the Same Dockerfile](<https://devfeed.tech/articles/understanding-docker-multi-stage-builds-installing-python-and-ruby-in-the-same-dockerfile-28156.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/docker/2019/11/22/understanding-docker-overlays-multiple-from-statements.html>)

Author: Fuzzygroup

Published: 2019-11-22T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Docker](<https://devfeed.tech/topics/docker.md>), [Dockerfile](<https://devfeed.tech/topics/dockerfile.md>), [Python](<https://devfeed.tech/topics/python.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Containers](<https://devfeed.tech/topics/containers.md>), [Deployment](<https://devfeed.tech/topics/deployment.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [apt](<https://devfeed.tech/tags/apt.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [deployment](<https://devfeed.tech/tags/deployment.md>), [docker](<https://devfeed.tech/tags/docker.md>), [docker-container](<https://devfeed.tech/tags/docker-container.md>), [docker-multi-stage-builds](<https://devfeed.tech/tags/docker-multi-stage-builds.md>), [python](<https://devfeed.tech/tags/python.md>), [python-dependencies](<https://devfeed.tech/tags/python-dependencies.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [ubuntu](<https://devfeed.tech/tags/ubuntu.md>)

## AI overview

This tutorial explains how to use Docker multi-stage builds to run Python and Ruby together in one Dockerfile. It describes isolating stages created by multiple FROM statements and intentionally copying the required executable and Python libraries into the Ruby-based image.

## Source excerpt

Now that I've come up to speed on Python, I have an application in production that uses both Python and Ruby. What it does isn't really important but getting it live posed an interesting deployment challenge due to the need to have both Python and Ruby concurrently. My initial attempt to make this was work was a native install using Python 3.7 and a fairly large set of Python dependencies on an Ubuntu 18.04 AWS instance. Unfortunately I kept hitting issues where, well, things just went to hell. This had me turn to Docker and my thinking was that I should be able to easily build a Dockerfile that supported both Python and Rails. chuckle. Nothing in Docker is actually easy but I got there. Note: The reason I needed Python is I was building a Twitter related application and I needed to use the truly excellent Twint library / executable. Python Dockerfile Attempt 1 I don't have a full record of this but I tried to pull in a traditional Python install using apt-get. This worked fairly horribly for reasons that escape me. Welcome to Overlays and Multiple From Statements My first attempt to make this work failed to work and it failed to really adopt the zen of Docker. One of the very cool features is that you can build up a Docker container with bits from different containers by using multiple from statements. This lets you have something like this: FROM continuumio/miniconda3:latest AS python RUN apt-get update && apt-get install build-essential python3-dev -y FROM ubuntu:latest FROM ruby:2.6.4-stretch The term for this is a Docker Multi Stage Build. The trick here is that the output from each FROM statement is logically isolated from each other. The reason for this is actually pretty simple - standard directory structures. Given that most *nix environments use similar top level structures like /opt, you simply can't combine things blindly - it needs to be an intentional choice using, drumroll, copy! Here's what this multi stage build stuff looked like: FROM continuumio/m