Created
January 31, 2023 17:47
-
-
Save barata0/5954f0c0f771d45da3e826dc65656399 to your computer and use it in GitHub Desktop.
docker-compose dev with same user and group as host
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
version: "3" | |
# to execute this compose for a user and group different than 1000:1000 | |
# UNAME=$(id -un) GNAME=$(id -gn) MY_UID=$(id -u) MY_GID=$(id -g) docker compose up --build | |
services: | |
app: | |
tty: true | |
build: | |
args: | |
UID: ${MY_UID} | |
GID: ${MY_GID} | |
UNAME: ${UNAME:-app} | |
GNAME: ${GNAME:-app} | |
context: . | |
user: ${UNAME:-app} | |
volumes: | |
- .:/workspace | |
working_dir: /workspace |
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 golang:1.19 | |
RUN apt-get update && apt-get -y install sudo | |
# get args from docker-compose args: or docker build --build-arg | |
ARG UNAME | |
ARG GNAME | |
ARG UID=1000 | |
ARG GID=1000 | |
# create the group and user | |
RUN groupadd -g $GID -o $GNAME | |
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME | |
# allow sudo and set new files mask to `-rw-r--r--` | |
RUN adduser $UNAME sudo && umask 0002 | |
# set a password to run sudo commands | |
RUN echo "${UNAME}:${UNAME}" | chpasswd |
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 | |
UNAME=$(id -un) GNAME=$(id -gn) MY_UID=$(id -u) MY_GID=$(id -g) docker compose up $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment