Creating a docker container for your Python app (using Rocker — R+Docker)

Creating a docker container for your Python app or R application is not that tough, But what happens when you developed an application that uses both languages, and what is the best approach to create the .dockerfile and achieve this without too much trouble? Keep reading to find out how.

Dockerizing a Py+R Application

What is .Dockerfile?

What should we consider when creating the Dockerfile in our case?

FROM ubuntu:18.04
R+Docker = Rocker
# Download and install library
RUN R -e "install.packages(c('shinydashboard', 'reticulate', 'shiny'))"
RUN ln -s /usr/bin/python3 /usr/bin/python && \
ln -s /usr/bin/pip3 /usr/bin/pip
FROM rocker/shiny:3.5.1
RUN apt-get update && apt-get install libcurl4-openssl-dev libv8-3.14-dev -y &&\
mkdir -p /var/lib/shiny-server/bookmarks/shiny
# Download and install library
RUN R -e "install.packages(c('shinydashboard', 'reticulate', 'shiny'))"
RUN ln -s /usr/bin/python3 /usr/bin/python && \
ln -s /usr/bin/pip3 /usr/bin/pip
RUN apt-get update
RUN apt-get install -y libpython-dev
RUN apt-get install -y libpython3-dev
# copy the app to the image
COPY shinyapps /root/app
COPY Rprofile.site /usr/local/lib/R/etc/Rprofile.site
# make all app files readable (solves issue when dev in Windows, but building in Ubuntu)
RUN chmod -R 755 /root/app
RUN chmod -R 755 /usr/local/lib/R/etc
EXPOSE 3838CMD ["R", "-e", "shiny::runApp('/root/app/app.R')"]

Deploy using Windows Powershell

Docker Build
Docker Run
Localhost:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jayasekara.Blog

Education articles from Data Engineering & Software Development to Lifestyle, Relationship and Love. We cover them all. Blog by Dilan Jayasekara,