Radek Sprta (Posts about docker)https://radeksprta.eu/categories/docker.atom2024-01-07T02:28:56ZRadek SprtaNikolaDeploy Docker Container from Gitlab CIhttps://radeksprta.eu/posts/deploy-docker-container-from-gitlab-ci/2020-09-12T10:46:27+02:002020-09-12T10:46:27+02:00Radek Sprta<div><p>Containers are all the rage nowadays and for a good reason. They help in unifying development and production environments. They also provide application encapsulation and isolation, among other things. But to get the most out of them, you should build and deploy them automatically. This post will show you how to do it using Gitlab CI and docker-compose.</p>
<p><a href="https://radeksprta.eu/posts/deploy-docker-container-from-gitlab-ci/">Read more…</a> (2 min remaining to read)</p></div>Run Nikola Blog in Dockerhttps://radeksprta.eu/posts/run-nikola-blog-in-docker/2020-08-28T08:27:20+02:002020-08-28T08:27:20+02:00Radek Sprta<div><p>A lot of you might have a blog or a personal website created by static generator. Thanks to their simple requirements (just a webserver, really), they are an ideal starting point for your dockerization journey. In this post, I will explain how to run a <a href="https://getnikola.com">Nikola</a> website in a container. Nikola powers this website and is my static generator of choice. But the steps should be fairly similar for other generators out there.</p>
<h3>Dockerfile</h3>
<p>The dockerfile I am using looks like this:</p>
<div class="code"><pre class="code literal-block"><span class="k">FROM</span><span class="w"> </span><span class="s">python:latest</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="s">builder</span>
<span class="c"># Copy the whole repository into Docker container</span>
<span class="k">COPY</span><span class="w"> </span>.<span class="w"> </span>.<span class="w"> </span>
<span class="c"># Build the blog</span>
<span class="k">RUN</span><span class="w"> </span>pip<span class="w"> </span>install<span class="w"> </span>nikola<span class="w"> </span><span class="se">\</span>
<span class="w"> </span><span class="o">&&</span><span class="w"> </span>run<span class="w"> </span>nikola<span class="w"> </span>build
<span class="k">FROM</span><span class="w"> </span><span class="s">nginx:alpine</span>
<span class="c"># Copy output to the default nginx directory</span>
<span class="k">COPY</span><span class="w"> </span>--from<span class="o">=</span>builder<span class="w"> </span>output<span class="w"> </span>/usr/share/nginx/html
<span class="c"># Copy nginx host configuration</span>
<span class="k">COPY</span><span class="w"> </span>nginx/default.conf<span class="w"> </span>/etc/nginx/conf.d/
</pre></div>
<p><a href="https://radeksprta.eu/posts/run-nikola-blog-in-docker/">Read more…</a> (2 min remaining to read)</p></div>Run Docker Container as Regular Userhttps://radeksprta.eu/posts/run-docker-container-regular-user/2017-10-21T14:21:13+02:002017-10-21T14:21:13+02:00Radek Sprta<div><p>Docker has become omnipresent in recent years. However, by default, it
requires root privileges to run containers. Obviously, this is not good
security-wise. But a simple change will allow you to run docker container as a
regular user. In the examples below, I am using Ubuntu 17.04, but the commands
should be the same for any Linux distribution.</p>
<h3>Add user to docker group</h3>
<p>First of all, what happens if you try to run docker without sufficient
privileges? You can see the output below:</p>
<div class="code"><pre class="code literal-block">$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Post https://%2Fvar%2Frun%2Fdocker.sock/v1.28/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
</pre></div>
<p>Docker allows users in docker group to run containers. You
can check which users the group contains by running:</p>
<div class="code"><pre class="code literal-block">$<span class="w"> </span>cat<span class="w"> </span>/etc/group<span class="w"> </span><span class="p">|</span><span class="w"> </span>grep<span class="w"> </span>docker<span class="w"> </span>docker:x:140:
</pre></div>
<p>In the example above, the
group does not include any users. Therefore, you need root privileges to run
containers, as shown by the error above. This is the default setting. To add
your user to the docker group, run this command:</p>
<div class="code"><pre class="code literal-block">sudo<span class="w"> </span>usermod<span class="w"> </span>-a<span class="w"> </span>-G<span class="w"> </span>docker<span class="w"> </span>user
</pre></div>
<p><a href="https://radeksprta.eu/posts/run-docker-container-regular-user/">Read more…</a> (1 min remaining to read)</p></div>