The code provides instructions for cloning a GitHub repository, building a Docker image, and running a Docker container to run a Jupyter notebook environment. The Docker container is run with interactive shell access, mapping port 8888 and mounting a directory to share files between the host machine and the container.
%%
bash
git
clone
https://github.com/megamindbrian/jupytangular2
docker
build - t
jupytangular. /
docker
run--
name
jupytangular - it - p
8888
:
8888 - v
~/jupytangular2/
notebooks /
:
/home/
jovyan / notebooks
jupytangular
docker
run--
name
jupytangular - it - p
8888
:
8888 - v
'C:\Users\brian.cullinan\Documents\jupytangular2\notebooks'
:
/home/
jovyan / notebooks
jupytangular
// Import required modules
import * as childProcess from 'child_process';
import * as path from 'path';
// Define constants for Git repository URL and Docker images
const GIT_REPO_URL = 'https://github.com/megamindbrian/jupytangular2';
const DOCKER_IMAGE_NAME = 'jupytangular';
// Define the directory path for the cloned repository
const REPO_DIR = path.join(process.env.HOME?? '', 'jupytangular2');
// Define the container name and ports
const CONTAINER_NAME = 'jupytangular';
const CONTAINER_PORT = 8888;
// Define the notebooks directory path
const NOTEBOOKS_DIR = path.join(process.env.HOME, 'jovyan', 'notebooks');
// Function to clone the Git repository
function cloneRepo(repoUrl: string, repoDir: string): void {
// Use childProcess to execute the Git clone command
childProcess.execSync(`git clone ${repoUrl} ${repoDir}`);
}
// Function to build the Docker image
function buildDockerImage(repoDir: string): void {
// Use childProcess to execute the Docker build command
childProcess.execSync(`docker build -t ${DOCKER_IMAGE_NAME} ${repoDir}`);
}
// Function to run the Docker container
function runDockerContainer(containerName: string, containerPort: number, repoDir: string, notebooksDir: string): void {
// Use childProcess to execute the Docker run command
childProcess.execSync(
`docker run --name ${containerName} -it -p ${containerPort}:${containerPort} -v ${repoDir}/notebooks/:/home/jovyan/notebooks/ ${containerName}`,
);
childProcess.execSync(
`docker run --name ${containerName} -it -p ${containerPort}:${containerPort} -v '${path.join(
process.env.HOME,
'Documents',
'jupytangular2',
'notebooks',
)}':/home/jovyan/notebooks/ ${containerName}`,
);
}
// Main function
function main(): void {
// Clone the Git repository
cloneRepo(GIT_REPO_URL, REPO_DIR);
// Build the Docker image
buildDockerImage(REPO_DIR);
// Run the Docker container
runDockerContainer(CONTAINER_NAME, CONTAINER_PORT, REPO_DIR, NOTEBOOKS_DIR);
}
// Call the main function
main();
git clone https://github.com/megamindbrian/jupytangular2
https://github.com/megamindbrian/jupytangular2
using the git clone
command.docker build -t jupytangular.
jupytangular
from the current directory (.
).docker run --name jupytangular -it -p 8888:8888 -v ~/jupytangular2/notebooks:/home/jovyan/notebooks jupytangular
jupytangular
from the jupytangular
image.-it
flag allows for interactive shell access.-p 8888:8888
flag maps port 8888 on the host machine to port 8888 in the container.-v
flag mounts the directory ~/jupytangular2/notebooks
on the host machine to /home/jovyan/notebooks
in the container.jupytangular
, is the name of the Docker image to run.docker run --name jupytangular -it -p 8888:8888 -v 'C:\Users\brian.cullinan\Documents\jupytangular2\notebooks':/home/jovyan/notebooks jupytangular
C:\Users\brian.cullinan\Documents\jupytangular2\notebooks
).