<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/" >

<channel>
	<title>docker &#8211; Random thoughts</title>
	<atom:link href="https://random.sphere.ro/tag/docker/feed/" rel="self" type="application/rss+xml" />
	<link>https://random.sphere.ro</link>
	<description>for when you get older and memory does&#039;t help you further</description>
	<lastBuildDate>Thu, 30 Jan 2020 20:28:15 +0000</lastBuildDate>
	<language>en-AU</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.5</generator>
	<item>
		<title>Docker / dockeish or how to give to someone ssh securely</title>
		<link>https://random.sphere.ro/dockeish/</link>
					<comments>https://random.sphere.ro/dockeish/#respond</comments>
		
		<dc:creator><![CDATA[iulian]]></dc:creator>
		<pubDate>Fri, 31 May 2019 19:16:21 +0000</pubDate>
				<category><![CDATA[Uncategorised]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[ssh]]></category>
		<guid isPermaLink="false">https://random.sphere.ro/?p=22</guid>

					<description><![CDATA[<p>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. FROM ubuntu:16.04 RUN apt-get update &#38;&#38; apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo &#039;root:screencast&#039; &#124; chpasswd RUN&#8230;</p>
<p class="read-more"><a class="readmore-btn" href="https://random.sphere.ro/dockeish/">Read More<span class="screen-reader-text">  Read More</span></a></p>
<p>The post <a rel="nofollow" href="https://random.sphere.ro/dockeish/">Docker / dockeish or how to give to someone ssh securely</a> appeared first on <a rel="nofollow" href="https://random.sphere.ro">Random thoughts</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2 id="build-an-eg_sshd-image">Build an <code class="" data-line="">eg_sshd</code> image</h2>
<p>The following <code class="" data-line="">Dockerfile</code> 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.</p>
<pre><code class="" data-line="">FROM ubuntu:16.04

RUN apt-get update &amp;&amp; apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo &#039;root:screencast&#039; | chpasswd
RUN sed -i &#039;s/PermitRootLogin prohibit-password/PermitRootLogin yes/&#039; /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed &#039;s@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g&#039; -i /etc/pam.d/sshd

ENV NOTVISIBLE &quot;in users profile&quot;
RUN echo &quot;export VISIBLE=now&quot; &gt;&gt; /etc/profile

EXPOSE 22
CMD [&quot;/usr/sbin/sshd&quot;, &quot;-D&quot;]
</code></pre>
<p>Build the image using:</p>
<div class="language-bash highlighter-rouge">
<div class="highlight">
<pre class="highlight"><code class="" data-line="">&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker build &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; eg_sshd &lt;span class=&quot;nb&quot;&gt;.&lt;/span&gt;
</code></pre>
<h2 id="run-a-test_sshd-container">Run a <code class="" data-line="">test_sshd</code> container</h2>
<p>Then run it. You can then use <code class="" data-line="">docker port</code> to find out what host port the container’s port 22 is mapped to:</p>
<pre><code class="" data-line="">docker run -v /host/directory:/container/directory -other -options image_name command_to_run</code></pre>
<div class="language-bash highlighter-rouge">
<div class="highlight">
<pre class="highlight"><code class="" data-line="">&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker run &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-P&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--name&lt;/span&gt; test_sshd eg_sshd
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker port test_sshd 22


0.0.0.0:49154
</code></pre>
</div>
</div>
<p>And now you can ssh as <code class="" data-line="">root</code> on the container’s IP address (you can find it with <code class="" data-line="">docker inspect</code>) or on port <code class="" data-line="">49154</code> of the Docker daemon’s host IP address (<code class="" data-line="">ip address</code> or <code class="" data-line="">ifconfig</code> can tell you that) or <code class="" data-line="">localhost</code> if on the Docker daemon host:</p>
<div class="language-bash highlighter-rouge">
<div class="highlight">
<pre class="highlight"><code class="" data-line="">&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ssh root@192.168.1.2 &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; 49154
&lt;span class=&quot;c&quot;&gt;# The password is ``screencast``.&lt;/span&gt;
root@f38c87f2a42d:/#
</code></pre>
<h2 id="environment-variables">Environment variables</h2>
<p>Using the <code class="" data-line="">sshd</code> daemon to spawn shells makes it complicated to pass environment variables to the user’s shell via the normal Docker mechanisms, as <code class="" data-line="">sshd</code> scrubs the environment before it starts the shell.</p>
<p>If you’re setting values in the <code class="" data-line="">Dockerfile</code> using <code class="" data-line="">ENV</code>, you need to push them to a shell initialization file like the <code class="" data-line="">/etc/profile</code> example in the <code class="" data-line="">Dockerfile</code> above.</p>
<p>If you need to pass<code class="" data-line="">docker run -e ENV=value</code> values, you need to write a short script to do the same before you start <code class="" data-line="">sshd -D</code> and then replace the <code class="" data-line="">CMD</code> with that script.</p>
<h2 id="clean-up">Clean up</h2>
<p>Finally, clean up after your test by stopping and removing the container, and then removing the image.</p>
<div class="language-bash highlighter-rouge">
<div class="highlight">
<pre class="highlight"><code class="" data-line="">&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker container stop test_sshd
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker container rm test_sshd
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;docker image rm eg_sshd

others: 
$ docker stats
$docker container ls -a
</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<p>The post <a rel="nofollow" href="https://random.sphere.ro/dockeish/">Docker / dockeish or how to give to someone ssh securely</a> appeared first on <a rel="nofollow" href="https://random.sphere.ro">Random thoughts</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://random.sphere.ro/dockeish/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
