Skip to content

Commit a9154be

Browse files
committed
Updated Dockerfile for latest alpine and set sshd host keys as a volume
1 parent 72f69a5 commit a9154be

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

Dockerfile

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
1-
FROM alpine:3.4
1+
FROM alpine:3.8
22

3-
MAINTAINER Carlos Bernárdez "carlos@z4studios.com"
3+
LABEL maintainer='Carlos Bernárdez <carlos@z4studios.com>'
44

5-
# "--no-cache" is new in Alpine 3.3 and it avoid using
6-
# "--update + rm -rf /var/cache/apk/*" (to remove cache)
7-
RUN apk add --no-cache \
8-
# openssh=7.2_p2-r1 \
9-
openssh \
10-
# git=2.8.3-r0
11-
git
12-
13-
# Key generation on the server
14-
RUN ssh-keygen -A
15-
16-
# SSH autorun
17-
# RUN rc-update add sshd
5+
RUN apk add --no-cache openssh git
186

197
WORKDIR /git-server/
208

9+
RUN mkdir -p keys-host/etc/ssh && \
10+
ssh-keygen -A -f keys-host && \
11+
mv keys-host/etc/ssh/* keys-host && \
12+
rm -rf keys-host/etc
13+
2114
# -D flag avoids password generation
2215
# -s flag changes user's shell
23-
RUN mkdir /git-server/keys \
24-
&& adduser -D -s /usr/bin/git-shell git \
25-
&& echo git:12345 | chpasswd \
26-
&& mkdir /home/git/.ssh
16+
RUN mkdir keys && \
17+
adduser -D -s /usr/bin/git-shell git && \
18+
echo git:12345 | chpasswd && \
19+
mkdir /home/git/.ssh
2720

2821
# This is a login shell for SSH accounts to provide restricted Git access.
2922
# It permits execution only of server-side Git commands implementing the
3023
# pull/push functionality, plus custom commands present in a subdirectory
3124
# named git-shell-commands in the user’s home directory.
3225
# More info: https://git-scm.com/docs/git-shell
33-
COPY git-shell-commands /home/git/git-shell-commands
26+
COPY git-shell-commands /home/git/git-shell-commands
3427

3528
# sshd_config file is edited for enable access key and disable access password
36-
COPY sshd_config /etc/ssh/sshd_config
37-
COPY start.sh start.sh
29+
COPY sshd_config /etc/ssh/sshd_config
30+
31+
COPY start.sh start.sh
32+
33+
EXPOSE 22
3834

39-
EXPOSE 22
35+
VOLUME ["/git/server/keys", "/git-server/keys-host", "/git-server/repos"]
4036

41-
CMD ["sh", "start.sh"]
37+
CMD ["sh", "start.sh"]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ How clone a repository:
4646

4747
$ git clone ssh://git@<ip-docker-server>:2222/git-server/repos/myrepo.git
4848

49+
How to list all repositories:
50+
51+
$ ssh git@<ip-docker-server>:2222
52+
4953
### Arguments
5054

5155
* **Expose ports**: 22

sshd_config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020

2121
# HostKey for protocol version 1
2222
#HostKey /etc/ssh/ssh_host_key
23-
# HostKeys for protocol version 2
24-
#HostKey /etc/ssh/ssh_host_rsa_key
25-
#HostKey /etc/ssh/ssh_host_dsa_key
26-
#HostKey /etc/ssh/ssh_host_ecdsa_key
27-
#HostKey /etc/ssh/ssh_host_ed25519_key
23+
#HostKeys for protocol version 2
24+
HostKey /git-server/keys-host/ssh_host_rsa_key
25+
HostKey /git-server/keys-host/ssh_host_dsa_key
26+
HostKey /git-server/keys-host/ssh_host_ecdsa_key
27+
HostKey /git-server/keys-host/ssh_host_ed25519_key
2828

2929
# Lifetime and size of ephemeral version 1 server key
3030
#KeyRegenerationInterval 1h

0 commit comments

Comments
 (0)