<?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/"
	>

<channel>
	<title>docker in docker Archives - gj</title>
	<atom:link href="https://blog.gaiterjones.com/tag/docker-in-docker/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/tag/docker-in-docker/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Fri, 17 Mar 2017 15:02:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Running Docker Apps in Docker Containers &#8211; docker in docker permissions</title>
		<link>https://blog.gaiterjones.com/docker-in-docker-permissions/</link>
					<comments>https://blog.gaiterjones.com/docker-in-docker-permissions/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Fri, 17 Mar 2017 18:49:11 +0000</pubDate>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[docker in docker]]></category>
		<category><![CDATA[permissions]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=1541</guid>

					<description><![CDATA[If you are looking at containerising PHP applications you might want to run another containerised application from within your container &#8211; run a docker application or command in a docker...<a class="more-link" href="https://blog.gaiterjones.com/docker-in-docker-permissions/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>If you are looking at containerising PHP applications you might want to run another containerised application from within your container &#8211; run a docker application or command in a docker container. Your native app might be encoding media on the fly via ajax requests using ffpmeg and you do not want to compile or install ffmpeg in your containerised app. It would be useful to run a containerised ffmpeg version within the container.</p>
<p>This is kind of a <em>quasi docker in docker</em> because we are not trying to create dockerised containers within a container, rather run a docker app from the docker host within a docker container.</p>
<p>Still with me? Good!</p>
<p>We give our container access to the host docker socket by sharing a volume (in this case docker.sock) with the container</p>
<pre class="brush: plain; title: ; notranslate">
  volumes:    
      - /var/run/docker.sock:/var/run/docker.sock
</pre>
<p>If we install the docker binaries within the container we can now run docker commands on the host i.e.:</p>
<pre>root@53f93be9ebbf:/#<strong> docker ps</strong>
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME S
53f93be9ebbf trusty_ubuntu "/bin/bash" 18 seconds ago Up 17 seconds...</pre>
<p>We are running docker ps as root, the problems start when you try and run docker as another user, for example www-data.</p>
<pre>root@53f93be9ebbf:/# sudo -u www-data docker ps
<strong>Got permission denied while trying to connect to the Docker daemon socket</strong> at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/json: dial unix /var/run/docker.sock: connect: permission denied</pre>
<p>We get a <strong>dial unix /var/run/docker.sock: connect: permission denied </strong>error.</p>
<p>Even if you add www-data to the docker group the permission problem persists.</p>
<p>If you take a look at /var/run/docker.sock in the container you will see the problem:</p>
<pre>root@53f93be9ebbf:/# ls -al /var/run/docker.sock
srw-rw---- 1 root 999 0 Jan 26 08:55 /var/run/docker.sock</pre>
<p>The container shows the group permissions for docker.sock (from the host) set to a group with an id of 999, and this group id does not exist in the container. We need to make sure the group id of the docker group in the container matches the group id of the docker group on the host</p>
<pre>addgroup --gid 999 docker
usermod -aG docker www-data</pre>
<p>The docker group now has the id of 999 and www-data is a member, the permissions in the container for docker.sock now look like this</p>
<pre>root@53f93be9ebbf:/# ls -al /var/run/docker.sock
srw-rw---- 1 root docker 0 Jan 26 08:55 /var/run/docker.sock</pre>
<p>And we can now execute docker ps as www-data</p>
<pre>root@53f93be9ebbf:/# sudo -u www-data docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53f93be9ebbf trusty_ubuntu "/bin/bash" 11 minutes ago Up 11 minutes ...</pre>
<p>Or run a <a href="https://github.com/jrottenberg/ffmpeg">containerised version of ffmpeg</a></p>
<pre>sudo -u www-data docker run jrottenberg/ffmpeg -stats \
 -i http://archive.org/download/thethreeagesbusterkeaton/Buster.Keaton.The.Three.Ages.ogv \
 -loop 0 \
 -final_delay 500 -c:v gif -f gif -ss 00:49:42 -t 5 - &gt; trow_ball.gif</pre>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-large" src="https://blog.gaiterjones.com/dropbox/trow_ball.gif" width="400" height="300" /></p>
<p>I can now exec docker run within the php code of the container app and run other docker container apps via ajax requests. You can add the group changes and install the docker binaries in the container using the following in your Dockerfile.</p>
<pre class="brush: plain; title: ; notranslate">
# &gt;&gt;&gt; DOCKER IN DOCKER
RUN set -x \
    &amp;&amp; cd /tmp \
    &amp;&amp; curl -L -o docker-latest.tgz  https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz \
    &amp;&amp; gzip -d docker-latest.tgz \
    &amp;&amp; tar -xvf docker-latest.tar \
    &amp;&amp; mv /tmp/docker/docker /usr/local/bin \
    &amp;&amp; rm -rf /tmp/docker docker-latest.tar \
    &amp;&amp; addgroup --gid 999 docker \
    &amp;&amp; usermod -aG docker www-data
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/docker-in-docker-permissions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		<enclosure url="http://archive.org/download/thethreeagesbusterkeaton/Buster.Keaton.The.Three.Ages.ogv" length="0" type="video/ogg" />

			</item>
	</channel>
</rss>
