Home

Awesome

SimpleContainerGenerator

Build Status Coverage

SimpleContainerGenerator automates the process of creating container images for using Julia packages.

The Julia packages inside the container image are automatically compiled by PackageCompiler into a custom Julia system image (sysimage) for faster load times.

These container images are especially useful for using Julia packages on systems without Internet access. But they are not limited to that use case. You can use these container images anywhere, as long as you have access to a tool such as Docker, Singularity, etc.

When building the Docker images, make sure that Docker Desktop is set to use at least 4 GB of memory (RAM). If you run into errors, you should try further increasing the amount of available memory.

Installation

import Pkg
Pkg.add("SimpleContainerGenerator")

Examples

In order to run these examples, you will need to have Docker installed on your computer.

Example 1

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    "Foo", # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    "Bar",
    "Baz",
]
julia_version = v"1.4.0"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           output_directory = pwd())

run(`docker build -t my_docker_username/my_image_name .`)

Example 2

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    (name = "Foo",), # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    (name = "Bar",),
    (name = "Baz",),
]
julia_version = v"1.4.0"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           output_directory = pwd())

run(`docker build -t my_docker_username/my_image_name .`)

Example 3

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    (name = "Foo", version = "1.2.3",), # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    (name = "Bar", version = "4.5.6",), # and replace the version numbers with actual version numbers for the packages
    (name = "Baz", version = "7.8.9",),
]
julia_version = v"1.4.0"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           output_directory = pwd())

run(`docker build -t my_docker_username/my_image_name .`)

Example 4

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    (name = "Foo", version = "1.2.3",), # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    (name = "Bar", version = "4.5.6",), # and replace the version numbers with actual version numbers for the packages
    (name = "Baz", rev     = "master",), # and replace "master" with the name of the branch you want to use
]
julia_version = v"1.4.0"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           output_directory = pwd())

run(`docker build -t my_docker_username/my_image_name .`)

Example 5

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    "Foo", # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    "Bar",
    "Baz",
]
no_test = [
    "Foo", # Replace Foo, etc. with the names of actual packages
    ]
exclude_packages_from_sysimage = [
    "Bar", # Replace Bar, etc. with the names of actual packages
    ]
julia_version = v"1.4.0"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           no_test = no_test,
                                           exclude_packages_from_sysimage = exclude_packages_from_sysimage,
                                           output_directory = pwd())

run(`docker build -t my_docker_username/my_image_name .`)

Example 6

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    "Foo", # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    "Bar",
    "Baz",
]
julia_version = v"1.4.0"
parent_image = "ubuntu:latest"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           output_directory = pwd(),
                                           parent_image = parent_image)

run(`docker build -t my_docker_username/my_image_name .`)

Example 7

import SimpleContainerGenerator

mkpath("my_image_name")
cd("my_image_name")

pkgs = [
    "Foo", # Replace Foo, Bar, Baz, etc. with the names of actual packages that you want to use
    "Bar",
    "Baz",
]
julia_version = v"1.4.0"
parent_image = "nvidia/cuda:11.2.0-devel-ubuntu20.04"

SimpleContainerGenerator.create_dockerfile(pkgs;
                                           julia_version = julia_version,
                                           output_directory = pwd(),
                                           parent_image = parent_image)

run(`docker build -t my_docker_username/my_image_name .`)

Docker cheatsheet

CommandDescription
docker build -t my_docker_username/my_image_name .Build an image from a given Dockerfile
docker run --name my_container_name -it my_docker_username/my_image_name /bin/bashStart a new container from a given image and enter a bash session
docker run --name my_container_name -it -v /Users/MYUSERNAME/Desktop/MYFOLDER:/mount/MYFOLDER my_docker_username/my_image_name /bin/bashStart a new container from a given image, mount a local directory, and enter a bash session
docker start -ai my_container_nameReenter a container after exiting it
docker container rm -f my_container_nameDelete a container
docker loginLogin to Docker Hub
docker push my_docker_username/my_image_namePush an image to Docker Hub

Related Packages

  1. PackageCompiler.jl

Acknowledgements