Code Monkey home page Code Monkey logo

devel-entrypoint's Introduction

devel-entrypoint

Docker container entrypoint for development environment.

This startup script allows you to run commands as a specified user by defining the user's information in environment variables when executing commands such as docker container run.

This script is inspired by the official Jupyter startup script and reuses some of its code, but it includes the following improvements:

  • The only change made to the container is creating init.sh in /usr/local/bin.
  • It can be easily installed in the container via the Dockerfile.
  • The specified user will be used if it already exists in the container, and will only be created if it does not exist.

This script is only compatible with Debian-based base images.

Install

Simply add the following script to the Dockerfile of the image where you want to add the user switching functionality:

RUN git clone https://github.com/wsuzume/devel-entrypoint.git \
    && cd devel-entrypoint \
    && /bin/bash install.sh

However, to run the above script, git and ca-certificates are required, and sudo is needed to execute init.sh. If these tools are not installed, add the following script beforehand:

RUN apt-get update --yes \
    && apt-get upgrade --yes \
    && apt-get install --yes --no-install-recommends \
        sudo git ca-certificates \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

Refer to the example folder for an installation example.

Usage

To enable the functionality, the user running the container must be root. Then, specify the following environment variables when starting the Docker container.

Environment Variable Function Default Value
INIT_USER User name morgan
INIT_UID User ID 1000
INIT_GROUP Group name (Same as INIT_USER if a non-existent GID is specified)
INIT_GID Group ID 100
GRANT_SUDO Grant sudo privileges (added if "yes" or "1") -

For example, if you want to start with the same user ID and group ID as the host, try running the following command:

docker container run -it --rm -e INIT_UID=`id -u` -e INIT_GID=`id -g` your_image init.sh

If you have any commands you want to run, append them after init.sh. For example, if you run the following command, you should get an output like this:

$ docker container run -it --rm -e INIT_UID=`id -u` -e INIT_GID=`id -g` your_image init.sh id
Entered init.sh with args: id
Create specified group: 'morgan' (5000)
Create specified user: 'morgan' (5000)
Running as morgan: id
uid=5000(morgan) gid=5000(morgan) groups=5000(morgan),100(users)

devel-entrypoint's People

Contributors

wsuzume avatar

Watchers

 avatar

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.