Showing posts with label docker. Show all posts
Showing posts with label docker. Show all posts

Tuesday, August 7, 2018

JupyterHub + oauthenticator Setup (docker)

Clone the latest code from jupyterhub oauthenticator

git clone https://github.com/jupyterhub/oauthenticator.git
cd oauthenticator/examples/full

Create env contains all necessary environment variables to be injected into the docker container

cat > env << EOF
OAUTH_CLIENT_ID=***********************
OAUTH_CLIENT_SECRET=********************************************
OAUTH_CALLBACK_URL=http://hostname:8000/hub/oauth_callback
GITHUB_HOST=github.internal.server 
GITHUB_HTTP=true
EOF

Create users

cat > userslist << EOF
wuf admin
fwu
EOF

Build the docker container

docker build -t jupyterhub-oauth .

Rename the old container

If there is an old container with the same name, we need to rename this container and change its restart policy to avoid starting both container competing for the same ports
docker rename jupyterhub jupyterhub-backup
docker update --restart=no jupyterhub-backup
docker ps -a
docker rename  jupyterhub 

Start the container

The following line starts the docker container with 20G base storage (default is 10G), set restart policy to be always yes, we set network to use host as when running spark there is many random ports to be used
docker run -d -it --storage-opt size=20G --network host --env-file=env --restart always jupyterhub-oauth

Enter the container

docker exec -it jupyterhub bash

Set the docker container timezone

/etc# echo "America/Toronto" > /etc/timezone
/etc# rm localtime
/etc# ln -snf /usr/share/zoneinfo/America/Toronto /etc/localtime
/etc# dpkg-reconfigure -f noninteractive tzdata

Tuesday, January 16, 2018

Docker Registry on Cloudian S3

This guide shows how to create a local docker registry on internal Cloudian S3 Storage.

Create a s3-registry-config.yaml config file for docker registry such as the sample config file below.

  • region, regionendpoint, v4auth, secure are critical values to be set exactly the same as the sample for it to work with Element's internal Cloudian S3.
  • By setting rootdirectory to / it will store the data under the following path in S3 bucket: $bucket/docker/registry/v2/
  • version: 0.1
    log:
      fields:
        service: registry
    storage:
      s3:
        accesskey: **************************
        secretkey: **************************************************************
        region: region1
        regionendpoint: http://s3internal.servername
        bucket: dockerreg
        rootdirectory: /
        v4auth: true
        secure: false
      cache:
        blobdescriptor: inmemory
    http:
      addr: :5000
      headers:
        X-Content-Type-Options: [nosniff]
    health:
      storagedriver:
        enabled: true
        interval: 10s
        threshold: 3
    

    start a registry container, note please run the following command from the path where the above configuration file located.

    docker run -d -p 5000:5000 --restart=always --name registry -v `pwd`/s3-registry-config.yaml:/etc/docker/registry/config.yml registry:2
    

    test the local docker registry

    # Pull the ubuntu:16.04 image from Docker Hub.
    docker pull ubuntu:16.04
    
    # Tag the image as localhost:5000/my-ubuntu. This creates an additional tag for the existing image. When the 
    # first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when 
    # pushing.
    docker tag ubuntu:16.04 localhost:5000/my-ubuntu
    
    # Push the image to the local registry running at localhost:5000:
    docker push localhost:5000/my-ubuntu
    
    # Remove the locally-cached ubuntu:16.04 and localhost:5000/my-ubuntu images, so that you can test pulling the # image from your registry. This does not remove the localhost:5000/my-ubuntu image from your registry.
    docker image remove ubuntu:16.04
    docker image remove localhost:5000/my-ubuntu
    
    # Pull the localhost:5000/my-ubuntu image from your local registry.
    docker pull localhost:5000/my-ubuntu
    
    # Validate image data are in the local registry
    aws s3 ls --recursive s3://dockerreg/ --endpoint-url http://s3internal.servername