As of December 2018, any customer with a valid SAS Viya order is able to package and deploy their SAS Viya software in Docker containers. SAS has provided a fully documented and supported project (or “recipe”) for easily building these containers. So how can you start? You can simply stop reading this article and go directly to the GitHub repository and follow the instructions there. Otherwise, in this article, Jeff Owens, a solutions architect at SAS, provides a little color commentary around the process in case it is helpful…
First of all, what is the point of these containers?
Well, at its core, remember SAS and its massively parallel, in-memory counterpart, Cloud Analytic Services (CAS) is a powerful runtime for data processing and analytics. A runtime is simply an engine responsible for processing and executing a particular type of code (i.e. SAS code). Traditionally, the SAS runtime would live on a centralized server somewhere and users would submit their “jobs” to that SAS runtime (server) in a variety of ways. The SAS server supports a number of different products, tasks, etc. – but for this discussion let’s just focus on the scenario where a job here is a “.sas” file, perhaps developed in an IDE-like Enterprise Guide or SAS Studio, and submitted to the SAS runtime engine via the IDE itself, a bash shell, or maybe even SAS’ enterprise grade scheduler and job management solution – SAS Grid. In these cases, the SAS and CAS servers are on dedicated, always-on physical servers.
The brave new containerized world in which we live provides us a new deployment model: submit the job and create the runtime server at the same time. Plus, only consume the exact resources from the host machine or the Kubernetes cluster the specific job requires. And when the job finishes, release those resources for others to use. Kubernetes and PaaS clusters are quite likely shared environments, and one of the major themes in the rise of the containers is the further abstraction between hardware and software. Some of that may be easier said than done, particularly for customers with very large volumes of jobs to manage, but it is indeed possible today with SAS Viya on Docker/Kubernetes.
Another effective (and more immediate) usage of this containerized version of SAS Viya is simply an adhoc, on-demand, temporary development environment. The container package includes SAS Studio, so one can quickly spin up a full SAS Viya programming sandbox – as well as the SAS & CAS runtimes. Here they can develop and test SAS code, and just as quickly tear the environment down when no longer needed. This is useful for users that: (a) don’t have access to an “always-on” environment for whatever reason, (b) want to try out experimental code that could potentially consume resources from a shared "always-on" sas environment, and/or (c) maybe their Kubernetes cluster has many more resources available than their always-on and they want to try a BIG job.
Yes, it is possible to deploy the entire SAS Viya stack (microservices and all) via Kubernetes but that discussion is for another day. This post focuses strictly on the SAS Viya programming components and running on a single machine Docker host rather than a Kubernetes cluster.
Build the container image
I will begin here with a fresh single machine RHEL 7.5 server running on Openstack. But this machine could have been running on any cloud or VM platform, and I could use any (modern enough) flavor of Linux thanks to how Docker works. My machine here has 8cpu, 16GB RAM, and a 50GB root volume. Less or more is fine. A couple of notes to help understand how to configure an instance:
- The final docker container image we will end up with will be ~10GB in size and like all docker images will live in /var/lib/docker/images by default.
- Yes, that is large for a container. Most of this size is just static bins and libs that support the very developed SAS language. Compare to an Anaconda image which is ~3.6GB.
- As for RAM, remember any tables loaded to CAS are loaded to memory (and will swap to disk as needed). So, your memory choice should be directly dependent on the data sizes you expect to work with.
- Similar story for cores – CAS code is multithreaded, so more cores = more parallelization.
The first step is to install Docker.
Following along with sas-container-recipes now, the first thing I should do is mirror the repo for my order. Note, this is not a required step – you could build this container directly from SAS repos if you wanted, but we’ll mirror as a best practice. We could simply mirror and serve it over the local filesystem of our build host, but since I promised color I’ll serve it over the web instead. So, these commands run on a separate RHEL server. If you choose to mirror on your build host, make sure you have the disk space (~30GB should be plenty). You will also need your SAS_Viya_deployment_data.zip file available on the SAS Customer Support site. Run the following code to execute the setup. Note: some of these commands will require root privileges, prefix with sudo as needed.
$ wget https://support.sas.com/installation/viya/35/sas-mirror-manager/lax/mirrormgr-linux.tgz $ tar xf mirrormgr-linux.tgz $ rm -f mirrormgr-linux.tgz $ mkdir -p /repos/viyactr $ mirrormgr mirror –deployment-data SAS_Viya_deployment_data.zip –path /repos/viyactr –platform x64-redhat-linux-6 –latest $ yum install httpd -y $ systemctl start httpd $ systemctl enable httpd $ ln -s /repos/viyactr /var/www/html/sas_repo
Next, I go ahead and clone the sas-containers-recipes repo locally and upload my SAS-Viya-deployment-data.zip file and I am ready to run the build command. As a bonus, I am also going to use my site’s (SAS’) sssd.conf file so my container will use our corporate Active Directory for authentication. If you do not need or want that integration you can skip the “vi addons/sssd.conf” line and change the “--addons” option to “addons/auth-demo” so your container seeds with a single “sasdemo:sasdemo” user:password instead.
$ # upload SAS_Viya_deployment_data.zip to this machine somehow $ DEPDATA=/path/to/SAS_Viya_Deployment_data.zip $ MIRROR=http://yourmirrorurl.com $ git clone https://github.com/sassoftware/sas-container-recipes.git $ cd sas-container-recipes/ $ vi addons/sssd.conf # <- paste in your site’s sssd.conf file $ build.sh \ --type single \ --zip $DEPDATA \ --mirror-url $MIRROR \ --addons “addons/auth-sssd”
The build should take about 45 minutes and produce a single container image for you (there might be a few images, but it is just one with a thin layer or two on top). You might want to give this image a new name (docker tag) and push it into your own private registry (docker push). Aside from that, we are ready to run it.
If you are curious, look in the addons directory for the other optional layers you can add to your container. Several tools are available for easily configuring connections to external databases.
Run the container
Here is the run command we can use to launch the container. Note the image name I use here is “sas-viya-programming:xxxxxx” – this is the image that has my sssd layer built on top of it.
$ docker run \ --detach \ --rm \ --env CASENV_CAS_HOST=$(hostname -f) \ --env CASENV_CAS_VIRTUAL_PORT=8081 \ --publish 5570:5570 \ --publish 8081:80 \ --name sas-viya-programming \ --hostname sas-viya-programming \ sas-viya-programming:xxxxxx
Connect to the container
And now, in a web browser, I can go to <hostname>:8081/SASStudio and I will end up in SAS Studio, where I can sign in with my internal SAS credentials. To stop the container, use the name you gave it: “docker stop sas-viya-programming”. Because we used the “--rm” flag the container will be removed (completely destroyed) when we stop it.
Note we are explicitly mapping in the HTTP port (8081:80) so we easily know how to get to SAS Studio. If you want to start up another container here on the same host, you will need to use a different port or else you’ll get an address already in use error. Also note we might be interested in connecting directly to this CAS server from something other than SAS Studio (localhost). A remote python client for example. We can use the other port we mapped in (5570:5570) to connect to the CAS server.
Persist the data
Running this container with the above command means anything and everything done inside the container (configuration changes, code, data) will not persist if the container stops and a new one started later. Luckily this is a very standard and easy to solve scenario with Docker and Kubernetes. Here are a couple of targets inside the container you might be interested in mounting a volume to:
- /data – this directory doesn’t necessarily exist but when you mount a volume into a container the target location will be created. So, you could call this target whatever you want, assuming it doesn’t exist yet. Bind mounting is tempting here and OK to do but consider the scenario when another user wants to run your container following instructions you provided them – better to use a Docker volume than force them to create the directory on the host. If you have an NFS location, bind mounting that makes sense
- /code – same spiel as with /data. Once you are in the container you can save your work and it will persist in the docker volume from run to run of your container.
Here is what an updated docker run command might look like with these volumes included:
$docker run \ --detach \ -rm \ --env CASNV_CAS_VIRTUAL_HOST=$(hostname -f) \ --env CASNV_CAS_VIRTUAL_PORT=8081 \ --volume mydata:/data \ --volume /nfsdata:/nfsdata \ # example syntax for bind mount instead of docker volume mount --volume mycode:/code \ --volume sastmp:/tmp \ --publish 5570:5570 \ --publish 8081:80 \ --name sas-viya-programming \ --hostname sas-viya-programming \ sas-viya-programming:xxxxxx
Can I run this on my laptop?
Yes. You would just need to install Docker on your laptop (go to docker.com for that). You can certainly follow the instructions from the top to build and run locally. You can even push this container image out to an internal registry so other users could skip the build and just run.
So far, we have only talked about the “ad-hoc” or “sandbox” dev type of use case for this container. A later article may cover how to run in batch mode or maybe we will move straight to multi-containers & Kubernetes. In the meantime though, here is how to submit a .sas program as a batch job to this single container we have built.
Give it a try!
Try creating your own image and deploying a container. Feel free to comment on your experience.
SAS Communities Article- Running SAS Analytics in a Docker container
SAS Global Forum Paper- Docker Toolkit for Data Scientists – How to Start Doing Data Science in Minutes!
SAS Global Forum Tech Talk Video- Deploying and running SAS in Containers
Hi, Can we get some guidance on license renewal for SAS Container for Analytics. We recently got the new license file from SAS Institute - SID File (SAS Installation Data File). How do we update the docker with this new SID information? Thanks in advance.
Well, these instructions are actually a bit dated now, so it kind of depends on how/when you built your image (a new version of sas-container-recipes gets pushed about once a month). But regardless, if you followed these instructions then your license would be "baked in" to your image. And to update your license, the easiest and recommended path would be to simply build a brand new image using the latest version of sas-container-recipes. If there is any reason that you cannot do that, please feel free to reach out to me directly at email@example.com for help.
Looking to get a "Visual Viya" single server/container build, any pointers/caveats? Is it even possible/advisable? Use case is a very much exploration and experimentation trial for a customer.
I am very late here, apologies, and wouldn't be surprised if you have already figured this out... but the answer to your question is yes it is possible to deploy Viya Visuals in containers. Note the plurality there though - this would be a multi-container deployment on kubernetes, not a single container.
Check out part 2 of this blog: https://blogs.sas.com/content/sgf/2019/06/10/deploying-the-full-sas-viya-stack-in-kubernetes/ and/or the recipes project itself: https://github.com/sassoftware/sas-container-recipes for more details.
Can we build docker container for SAS 9.4 Grid environment ? Do we have any specific instructions ?
While these instructions were specific to building a SAS Viya container, this container DOES include a SAS 9.4 engine natively so it can be used, for example, for batch 9.4 job execution.
There is a way to build a 9.4 container only, but that process is different than what is described in this blog. You could reference this documentation for help: https://go.documentation.sas.com/?docsetId=containers&docsetTarget=titlepage.htm&docsetVersion=9.4&locale=en
Here is a link to a SAS Global Forum paper on SAS 9.4 on containers.
I also found a couple of other blog posts on the subject: The power and potential of simplicity: SAS 9.4 and Containers and Analytics in the Cloud gets a whole lot easier with SAS Analytics for Containers.