Skip to content

Instantly share code, notes, and snippets.

@viniciusgonmelo
Last active June 11, 2023 06:33
Show Gist options
  • Save viniciusgonmelo/3f6f53237030730e3a2b6aaf97deee44 to your computer and use it in GitHub Desktop.
Save viniciusgonmelo/3f6f53237030730e3a2b6aaf97deee44 to your computer and use it in GitHub Desktop.
Servidor Git com Docker (Dockerfile e docker build/run)
# https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
FROM debian:11
LABEL name="git"
ARG SSH_PUB_KEY
RUN apt update && apt install openssh-server git -y
RUN useradd -rm -s /bin/bash git && echo 'git:git' | chpasswd
WORKDIR /home/git
USER git
RUN mkdir .ssh && chmod 700 .ssh && touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys && echo "$SSH_PUB_KEY" > .ssh/authorized_keys
USER root
RUN mkdir /srv/git && echo 'cd /srv/git' >> /home/git/.bashrc
RUN sed -i 's/#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
RUN sed -i 's/#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]
# docker build -t git --build-arg SSH_PUB_KEY="$(cat ./key.pub)" .
# docker network create --subnet="$NET_GIT" git
# docker run \
# -d \
# -v repos:/srv/git:rw \
# --name git \
# --network git \
# --restart unless-stopped \
# git
# docker exec -u 0 git chown git /srv/git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment