 Docker containers with R and Python. Having code in containers is a valuable tool for data scientists. It allows easier transfer of scripts used for modeling and data prep to the engineering team. Containers harden your scripts. If the code is in a container, then you can be more confident that if your container works, then the code will work. Information regarding Docker containers for R or Python is straightforward. I may do a video on each of these at some other point, but the focus of this video is to show how to make Docker containers that allow code that's both in R and in Python. To follow along with this tutorial, you'll need three things. Docker. Go to Docker's website to get instructions on how to install Docker for your operating system. Two, you will also want to go to hub.docker.com to get a login. This login is used when you run Docker run. And third, if you want, you can add yourself to the Docker group. Let's dive in. At the root of the directory, you will see the Docker file. This is where the sequence of operations are defined. Always build on an R image. The first command in the Docker file pulls the R image from rocker, tidyverse. We do this because the tidyverse has many dependencies. If it were to pull a Python image, then we'd have to do all the heavy lifting to make sure that we have R installed and all the tidyverse dependencies. So we're going to be smart about the way we work and pull the image that contains more dependencies so we don't have to write that in our own Docker file. The next command in the Docker file installs Python 3 and PIP 3. Next, we'll install R's forecast package. This is the package that we'll use for this demonstration. We'll use this with the install to R command. This command is probably new to some R users, at least it was to me. Install to R is a command to install in our library from the command line. That's if you have little R installed. It's worth mentioning now that the statements that follow run in a Docker file are command line statements. After installing the R packages we need, we can make a new directory and set that directory as our current directory. We will see later that this is the directory we will put our files into. On line 24, the R script is copied into user bin. The final line runs the main.py file. Let's look inside the main.py file. You will not see anything notable here. The idea here is that a lot of software has APIs and many of these APIs have a Python API. For example, say we wanted to do a data pull. Say the API to pull this data is a Python API. You can add the necessary code and configurations for the Python API in a directory, in this directory, and call it in the main.py file. Once we have all the data you need to get your R code running, we can kick off the R script from the command line using Python's OS.System method. Let's see what the R script is doing. This R script is using the forecast package to forecast some series of data. Though this is not complicated here, you can imagine reading a CSV that some upstream Python code wrote. Then you can write output of the R script. In this way, the two languages can work together to solve problems. This is it for the scripts. Now let's build the image and run. I normally skim through the man pages to find the command I'm looking for. In many Docker tutorials, you'll see that the Docker container is running an interactive session. This is not needed here. We just need to run our script to execute and print the results of our forecast. No interactive session. I also tagged the image along with a version number. One gotcha that is easy to miss is that I have a dot at the end of the command. This means that we want to run the Docker file that is located in the current directory. As you probably noticed, there is a good deal of command line and basic Linux knowledge that can help you write better Docker files. For example, we move the R script to the user bin directory because this is where you put things when you want to execute them. Also, all the commands after run are command line statements. Knowing more command line statements may give you more flexibility. To kick off the R script from Python, we use OS.system, which calls the command line. It is a general rule of thumb that getting immersed in GNU slash Linux pays dividends even for data scientists. Now we run the Docker run command. The general syntax is Docker run with the vflag saying that we want to attach a volume to the container. The volume that we want to attach is our home directory. So I'm just doing the dollar sign, pwd, which is print the working directory to the container directory that we made earlier, the app directory. And then we say what image we want to run. At this point, if everything works, you will find a forecast in std out. This is it. Clone this code from GitHub and make some changes that suit your needs.