Skip to content

Instantly share code, notes, and snippets.

@maple3142
Last active December 1, 2024 17:28
Show Gist options
  • Save maple3142/483ed65d0fb84bb836ceb97d013e940e to your computer and use it in GitHub Desktop.
Save maple3142/483ed65d0fb84bb836ceb97d013e940e to your computer and use it in GitHub Desktop.
Sage + macaulay2 in docker

Based on https://github.com/Macaulay2/M2/blob/master/M2/BUILD/docker/README.md

Need to fix Dockerfile then just make build

The entrypoint script is M2-docker

Run sage with

> SAGE_MACAULAY2_COMMAND=/path/to/M2-docker sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.4, Release Date: 2024-07-19                    │
│ Using Python 3.12.7. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: macaulay2('1+1')
2
sage:

Or just put this in your ~/.sage/init.sage:

os.environ['SAGE_MACAULAY2_COMMAND'] = '/path/to/M2-docker'
# Time usage: <5min
# Net usage: ~200MB
# Disk usage: <800MB docker image
FROM ubuntu:20.04
# Setting up Macaulay2 repository
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends software-properties-common apt-transport-https && \
add-apt-repository ppa:macaulay2/macaulay2 && apt-get update && apt-get clean
# Install Macaulay2
RUN apt-get install -y --no-install-recommends macaulay2 && apt-get clean
# Install optional packages
RUN apt-get install -y emacs elpa-macaulay2 bash-completion curl git mlocate && \
apt-get clean && updatedb
# Add non-root user for running Macaulay2
RUN useradd -G sudo -g root -u 1000 -m macaulay && echo "macaulay ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
USER 1000:0
# Setting environment variables
ENV LD_LIBRARY_PATH /usr/lib/Macaulay2/lib
ENV PATH /usr/libexec/Macaulay2/bin:${PATH}
WORKDIR /home/macaulay
ENTRYPOINT emacs
#!/bin/sh
docker run -v /tmp:/tmp --rm -it --entrypoint M2 m2 "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment