Giter VIP home page Giter VIP logo

dockersh's Introduction

dockersh

A shell which places users into individual docker containers

Usage

usage: dockersh [-h] [--version] [-i IMAGE] [-n NAME] [-t] [--shell SHELL]
                [--home HOME]

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -i IMAGE, --image IMAGE
                        base image to be used
  -n NAME, --name NAME  container name
  -t, --temporary       execute in temporary container
  --shell SHELL         shell to start inside the container
  --home HOME           user home directory

Examples

  • Change the login shell of a users to dockersh with:
chsh -s /usr/local/bin/dockersh <username>

This change implies that whenever this user tries to logon to the host from outside (using ssh) he will be redirected into his personal dockersh container instead to the host itself. Therefore, he works in an encapsulated environment.

  • Start a containerized shell with a specific base image:
dockersh -i nvidia/cuda

will give you an interactive shell.

Installation

Requirements

Make sure all dockersh users have the permissions to interact with the Docker daemon.

You can install dockersh using the provided install script:

sudo <path to dockersh>/install.sh

Test your installation:

docker pull ubuntu
dockersh -t

This should give you an interactive shell in a temporary container.

To enable scp,rsync,sftp for all users, configure rssh as follows:

sudo echo "
allowscp
allowsftp
allowrsync
" > /etc/rssh.conf

Configuration

The default configuration for each user is managed via /etc/dockersh.ini.

Example

[DEFAULT]
image = ubuntu:latest
suffix = _${USER}
shell = /bin/bash
homedir = ${HOME}
greeting = dockersh (github.com/sleeepyjack/dockersh)

[myuser1]
image = alpine:latest
shell = /bin/ash

[myuser2]
image = nvidia/cuda:latest
homedir  = /somewhere/myuser1

Permission Errors - or: Make Container User = Host User

By default, docker runs as root, hence in the container, the home-directory of the user will be not accessable by default and has to be chowned at first. To prevent this problem due to permissions we encourage you to use the image template of this repository, that maps the internal docker-user to the host-user.

  1. Just type
	./make_user_image.sh ubuntu_user ubuntu

to create a local image named 'ubuntu_user' that - together with dockersh - creates a user with the same uid and gid of the host user that runs dockersh. 2. Change your /etc/dockersh.ini to use the ubuntu_user-image.

Note: By default, it will overwrite the entrypoint of the 'cloned' image.

Admin commands

First, register in dockersh.ini as an administrator.

    [ADMIN]
    names = admin_user1

Log into host-system:

    ssh myserver admin

Log in as another user:

    USER=otheruser dockersh

Backup

The home directory of the user is mounted inside of the container and can be used to store data persistently. However, since the container state is non-persistent, make sure you commit your running containers from time to time.

dockersh provides an backup script which commits the current state of every dockersh container to the local registry. You can simply add the following line to your crontab:

0   0   *   *   *   python3 <path to dockersh>/commit_all.py

This calls the backup script once every day at 12 AM.

Disclaimer

This software does not guarantee perfect encapsulation and security, since Docker itself may have some security issues.

dockersh's People

Contributors

sleeepyjack avatar da-h avatar sbrodehl avatar

Stargazers

 avatar  avatar red thing avatar DCODEV1702 avatar  avatar  avatar AnyKeyShik Rarity avatar Pablo P. avatar Thomas avatar Jens Kohl avatar RafnexJr avatar Eric Poelke avatar Jonathan E. Magen avatar Devon Hubner avatar Malar Kannan avatar Nogweii avatar Chris Francy avatar Jordan Loehr avatar Vladislav Tolstykh avatar andreichernov avatar wumb0 avatar A.W.MyHR avatar david watson avatar Joshua Eichorn avatar mi2428 avatar Benjamin Arntzen avatar  avatar André Müller avatar  avatar

Watchers

James Cloos avatar andreichernov avatar  avatar Florian Roscher avatar  avatar

dockersh's Issues

HOME is not passed to configparser initialization

USER is passed in, but HOME is not. This causes the variable replacement in the dockersh.ini to fail with the following error.

configparser.InterpolationMissingOptionError: Bad value substitution: option 'homedir' in section 'DEFAULT' contains an interpolation key 'HOME' which is not a valid option name. Raw value: '${HOME}'

https://github.com/sleeepyjack/dockersh/blob/master/dockersh#L115
Perhaps add HOME: os.environ['HOME'] to the config_envir dict.

os.getlogin problem

First time running dockersh -t after fresh install will give

Traceback (most recent call last): File "/usr/local/bin/dockersh", line 22, in <module> user = os.getlogin() FileNotFoundError: [Errno 2] No such file or directory

found a workaround from some other github issue and stackoverflow answer suggesting to replace os.getlogin in line 22 of dockersh to

import pwd
import os

getlogin = lambda: pwd.getpwuid(os.getuid())[0]
user = getlogin()

this will only eliminate the error above and will ran into the issue #5 ...
any suggestions on how to make the whole dockersh working?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.