1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #8005 from SvenDowideit/document-sshd-env-vars

Document how to pass ENV vars to the user's shell
This commit is contained in:
Fred Lifton 2014-09-15 12:44:56 -07:00
commit c892423209
2 changed files with 35 additions and 8 deletions

View file

@ -1,13 +1,17 @@
# sshd # sshd
# #
# VERSION 0.0.1 # VERSION 0.0.2
FROM ubuntu:12.04 FROM ubuntu:14.04
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com" MAINTAINER Sven Dowideit <SvenDowideit@docker.com>
RUN apt-get update && apt-get install -y openssh-server RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd RUN mkdir /var/run/sshd
RUN echo 'root:screencast' |chpasswd RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22 EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"] CMD ["/usr/sbin/sshd", "-D"]

View file

@ -4,22 +4,27 @@ page_keywords: docker, example, package installation, networking
# Dockerizing an SSH Daemon Service # Dockerizing an SSH Daemon Service
## Build an `eg_sshd` image
The following `Dockerfile` sets up an SSHd service in a container that you The following `Dockerfile` sets up an SSHd service in a container that you
can use to connect to and inspect other container's volumes, or to get can use to connect to and inspect other container's volumes, or to get
quick access to a test container. quick access to a test container.
# sshd # sshd
# #
# VERSION 0.0.1 # VERSION 0.0.2
FROM ubuntu:14.04 FROM ubuntu:14.04
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com" MAINTAINER Sven Dowideit <SvenDowideit@docker.com>
RUN apt-get update && apt-get install -y openssh-server RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22 EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"] CMD ["/usr/sbin/sshd", "-D"]
@ -27,6 +32,8 @@ Build the image using:
$ sudo docker build -t eg_sshd . $ sudo docker build -t eg_sshd .
## Run a `test_sshd` container
Then run it. You can then use `docker port` to find out what host port Then run it. You can then use `docker port` to find out what host port
the container's port 22 is mapped to: the container's port 22 is mapped to:
@ -42,6 +49,22 @@ with `docker inspect`) or on port `49154` of the Docker daemon's host IP address
# The password is ``screencast``. # The password is ``screencast``.
$$ $$
## Environment variables
Using the `sshd` daemon to spawn shells makes it complicated to pass environment
variables to the user's shell via the simple Docker mechanisms, as `sshd` scrubs
the environment before it starts the shell.
If you're setting values in the Dockerfile using `ENV`, you'll need to push them
to a shell initialisation file like the `/etc/profile` example in the Dockerfile
above.
If you need to pass`docker run -e ENV=value` values, you will need to write a
short script to do the same before you start `sshd -D` - and then replace the
`CMD` with that script.
## Clean up
Finally, clean up after your test by stopping and removing the Finally, clean up after your test by stopping and removing the
container, and then removing the image. container, and then removing the image.