Skip to content

Commit 8ca5ad4

Browse files
committed
Merge remote-tracking branch 'origin/docker-filter'
2 parents 00de671 + 9bfe112 commit 8ca5ad4

6 files changed

+1651
-103
lines changed

Dockerfile

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
FROM gliderlabs/alpine
1+
FROM node:9-onbuild as build
22

3-
WORKDIR /src
4-
ADD . .
5-
6-
RUN apk --update add python make g++ nodejs \
7-
&& npm install \
8-
&& apk del make gcc g++ python \
9-
&& rm -rf /tmp/* /var/cache/apk/* /root/.npm /root/.node-gyp
3+
CMD ["npm", "start"]
104

5+
FROM alpine:3.6
6+
COPY --from=build /usr/src/app /usr/src/app
117

12-
# make coffee executable
13-
RUN chmod +x ./node_modules/coffee-script/bin/coffee
8+
RUN apk update \
9+
&& apk add nodejs nodejs-npm \
10+
&& rm -rf /tmp/* /var/cache/apk/* /root/.npm /root/.node-gyp
1411

1512
# Connect to container with name/id
1613
ENV CONTAINER=
@@ -32,4 +29,5 @@ ENV HTTP_PORT=8022
3229

3330
EXPOSE 22 8022
3431

32+
WORKDIR /usr/src/app
3533
CMD ["npm", "start"]

README.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Want to SSH into your container right away? Here you go:
55

66
$ docker run -d -p 2222:22 \
77
-v /var/run/docker.sock:/var/run/docker.sock \
8-
-e CONTAINER=my-container -e AUTH_MECHANISM=noAuth \
8+
-e FILTERS={\"name\":[\"my-container\"]} -e AUTH_MECHANISM=noAuth \
99
jeroenpeeters/docker-ssh
1010

1111
$ ssh -p 2222 localhost
@@ -44,19 +44,20 @@ message if you whish to contribute to this project.
4444
- [x] Execute single command
4545
- [x] HTTP API
4646
- [x] Web terminal
47-
- [ ] Customize the MOTD
4847
- [x] Simple user authentication; one user/password
4948
- [x] Authenticate users by username and password
5049
- [x] Authenticate users by username and public key
50+
- [x] Run commands as specific user
51+
- [x] Use Docker filter to target a container
52+
- [ ] Customize the MOTD
5153
- [ ] Secure copy implementation (SCP)
5254
- [ ] Secure FTP implementation (SFTP)
5355
- [ ] Access multiple containers
54-
- [x] Run commands as specific user
5556

5657
# Add SSH capabilities to any container!
5758
Let's assume you have a running container with name 'web-server1'. Run the following command to start Docker-SSH:
5859

59-
docker run -e CONTAINER=web-server1 -e AUTH_MECHANISM=noAuth \
60+
docker run -e FILTERS={\"name\":[\"web-server-1\"]} -e AUTH_MECHANISM=noAuth \
6061
--name sshd-web-server1 -p 2222:22 --rm \
6162
-v /var/run/docker.sock:/var/run/docker.sock \
6263
jeroenpeeters/docker-ssh
@@ -131,7 +132,7 @@ by setting `AUTH_USER` and `AUTH_PASSWORD`.
131132

132133
$ docker run -d -p 2222:22 \
133134
-v /var/run/docker.sock:/var/run/docker.sock \
134-
-e CONTAINER=my-container -e AUTH_MECHANISM=simpleAuth \
135+
-e FILTERS={\"name\":[\"my-container\"]} -e AUTH_MECHANISM=simpleAuth \
135136
-e AUTH_USER=jeroen -e AUTH_PASSWORD=1234 \
136137
jeroenpeeters/docker-ssh
137138

@@ -146,7 +147,7 @@ It is a single string with semicolon (;) separated user:password pairs.
146147

147148
$ docker run -d -p 2222:22 \
148149
-v /var/run/docker.sock:/var/run/docker.sock \
149-
-e CONTAINER=my-container -e AUTH_MECHANISM=multiUser \
150+
-e FILTERS={\"name\":[\"my-container\"]} -e AUTH_MECHANISM=multiUser \
150151
-e AUTH_TUPLES="jeroen:thefather;luke:theforce" \
151152
jeroenpeeters/docker-ssh
152153

@@ -162,7 +163,7 @@ The name of the authorized_keys file is configured by setting `AUTHORIZED_KEYS`.
162163
$ docker run -d -p 2222:22 \
163164
-v /var/run/docker.sock:/var/run/docker.sock \
164165
-v ./authorized_keys:/authorized_keys
165-
-e CONTAINER=my-container -e AUTH_MECHANISM=publicKey \
166+
-e FILTERS={\"name\":[\"my-container\"]} -e AUTH_MECHANISM=publicKey \
166167
-e AUTHORIZED_KEYS=/authorized_keys \
167168
jeroenpeeters/docker-ssh
168169

@@ -175,6 +176,12 @@ By default the shell user will be the user from the USER directive in the Docker
175176
If you whish to override this you can specify `SHELL_USER` as an environment variable
176177
to Docker-SSH. **Note: This user MUST already exist in the container, otherwise Docker-SSH will fail.**
177178

179+
# Docker Filter
180+
Docker-SSH uses the filter argument of `docker ps` to target a specific container. You should make sure
181+
that the filter matches the intended target container. If the filter matches multiple containers, the first
182+
one will be used. See [https://docs.docker.com/engine/api/v1.33/#operation/ContainerList](https://docs.docker.com/engine/api/v1.33/#operation/ContainerList). For backwards compatibility the `CONTAINER`
183+
environment variable passed to Docker-SSH is now implemented as a filter on container name.
184+
178185
# Server Identity and Security
179186
The SSH server needs an RSA/EC private key in order to secure the connection and identify itself to clients.
180187
The Docker-SSH container comes with a default RSA key that will be used. If you want, you can provide your own
@@ -188,7 +195,8 @@ argument in order to know for which container to provide SSH. Mounting the Docke
188195

189196
Argument | Default | Description
190197
---------------|----------|------------------------------------------------------
191-
CONTAINER | None | *name* or *id* of a running container
198+
FILTER | None | Docker filter to target a container
199+
CONTAINER | None | *name* of a running container. **deprecated**, use FILTER
192200
CONTAINER_SHELL| bash | path to a shell.
193201
AUTH_MECHANISM | None | name of the authentication mechanism, see [User Authentication](#user-authentication)
194202
KEYPATH | ./id_rsa | path to a private key to use as server identity

0 commit comments

Comments
 (0)