Document how to pass ENV vars to the user's shell

As this is a somewhat common question.

Docker-DCO-1.1-Signed-off-by: Sven Dowideit <SvenDowideit@docker.com> (github: SvenDowideit)
This commit is contained in:
Sven Dowideit 2014-09-12 13:30:20 +10:00
parent 32b5d145fa
commit 0517099a91
2 changed files with 35 additions and 8 deletions

View File

@ -1,13 +1,17 @@
# sshd
#
# VERSION 0.0.1
# VERSION 0.0.2
FROM ubuntu:12.04
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"
FROM ubuntu:14.04
MAINTAINER Sven Dowideit <SvenDowideit@docker.com>
RUN apt-get update && apt-get install -y openssh-server
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
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
## Build an `eg_sshd` image
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
quick access to a test container.
# sshd
#
# VERSION 0.0.1
# VERSION 0.0.2
FROM ubuntu:14.04
MAINTAINER Thatcher R. Peskens "thatcher@dotcloud.com"
FROM ubuntu:14.04
MAINTAINER Sven Dowideit <SvenDowideit@docker.com>
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
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
CMD ["/usr/sbin/sshd", "-D"]
@ -27,6 +32,8 @@ Build the image using:
$ 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
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``.
$$
## 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
container, and then removing the image.