Created
June 2, 2020 02:37
-
-
Save joshbode/341ab27f7e4fa4b5348020865ec84dfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.8 | |
# ... | |
ADD entrypoint.sh /usr/local/bin | |
ENTRYPOINT ["bash"] | |
CMD ["-l"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e | |
USER_NAME=${USER_NAME:-user} | |
USER_ID=${USER_ID:-1000} | |
GROUP_NAME=${GROUP_NAME:-${USER_NAME}} | |
GROUP_ID=${GROUP_ID:-${USER_ID}} | |
if [[ -d /home/${USER_NAME} ]]; then | |
USER_OPTS=-M | |
else | |
USER_OPTS=-m | |
fi | |
useradd ${USER_OPTS} -s /bin/bash -u ${USER_ID} ${USER_NAME} | |
if [[ "${DOCKER_GID}" != "" ]]; then | |
groupadd -g ${DOCKER_GID} docker | |
usermod -aG ${DOCKER_GID} ${USER_NAME} | |
fi | |
if (( $# )); then | |
exec runuser -u ${USER_NAME} -- "$@" | |
else | |
exec runuser -u ${USER_NAME} -- bash -l | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
set -e | |
BASE_DIR=${PWD}/$(dirname "$0") | |
USER_NAME=$(id -un) | |
USER_ID=$(id -u) | |
DOCKER_GID=$(getent group docker | cut -d: -f3) | |
docker run \ | |
--rm -it \ | |
--name=run \ | |
--entrypoint entrypoint.sh \ | |
--network host \ | |
--workdir /src \ | |
-e USER_NAME=${USER_NAME} \ | |
-e USER_ID=${USER_ID} \ | |
-e DOCKER_GID=${DOCKER_GID} \ | |
-v "${HOME}:/home/${USER_NAME}" \ | |
-v "${BASE_DIR}":/src \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment