You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aney.co.uk/guides/docker-install.html

120 lines
5.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="A guide to adding a free SSL certificate to your website(s) using cerbot, and automatically renewing them">
<meta name="keywords" content="Blog, articles, guide, certbot, SSL, secure certificate, website">
<meta name="author" content="Nathan (Aney) Steel">
<meta name="theme-color" content="white">
<meta name="theme-color" content="black">
<link rel="stylesheet" type="text/css" href="/main.css">
<link rel="icon" type="image/png" href="/images/favicon.svg">
<title>Docker Install (inc. Portainer)</title>
</head>
<body>
<header>
<a href="#main" class="vh">Jump directly to main content</a>
<h1>Docker Install (inc. Portainer)</h1>
<input id="burger-toggle" type="checkbox"/>
<label class="burger-container" for="burger-toggle"><div class="burger"></div><span class="sr">Burger menu</span></label>
<hr/>
<nav>
<a href="/">home</a>
<a href="/about.html">about</a>
<a href="/projects.html">projects</a>
<a href="/blog/">blog</a>
<a href="/sitemap.html">misc</a>
<a href="/support.html">support</a>
</nav>
<hr/>
</header>
<main id="main">
<section>
<p>Docker's pretty cool. Containers are a simple way to, well containerise applications. They're essentially a virtual machine with less overhead.</p>
<p>This guide assumes you have a <a href="/guides/server-install-debian.html" target="_blank" rel="noopener">debian install</a>, either physical or a VM (I recommend a VM).</p>
<h2>Installing Docker</h2>
<p>The following is the script I use for my docker installations. Copy/Paste or throw into a file and execute it.</p>
<pre><code>sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin</code></pre>
<p>This will download add the required keyring, download the correct docker version for your PCs arhitecture, and the sources, and download the required packages.</p>
<p>With this docker is now installed and ready to go!</p>
<h2>Installing your first container, Portainer</h2>
<p>Portainer is a web-GUI for managing docker containers, so I figure it's a good place to start.</p>
<h3>Docker Run</h3>
<p>Not recommended. Use <a href="#compose">compose</a>.</p>
<pre><code>docker run -d \
-p 9443:9443 \
--name portainer \
--restart unless-stopped \
-v data:/data \
-v /var/run/docker.sock:/var/run/docker.sock \
portainer/portainer-ce:latest</code></pre>
<h3 id="compose">Docker Compose</h3>
<p>My preferred way of setting up, and running containers. It makes it more managable, and easier to follow.
There are a few more 'steps' here, but that's more-so for managing the containers than a requirement.</p>
<p>First off we'll create a 'docker' directory, with a 'portainer' directory within it in our home directory.</p>
<pre><code>mkdir -p ~/docker/portainer && cd ~/docker/portainer && touch docker-compose.yml</code></pre>
<p>Next from within the portainer directory, open up/create <code>docker-compose.yml</code>.
Use your preferred text editor here, I like vim, so I'll be using it in the snippet.</p>
<p>Paste the following into the file, and save it.</p>
<pre><code>services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
restart: unless-stopped
security_opt:
- no-new-privileges:true
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data:/data
ports:
- 9443:9443</code></pre>
<p>Next we'll run docker compose, which will do as the run command did, pulling the container (if not already done so), and running it.</p>
<pre><code>sudo docker compose up -d</code></pre>
<h3>Accessing Portainer</h3>
<p>Once this has been run successfully you should be able to access portainer using the IP of the docker host, or localhost (if running docker on the same PC).</p>
<p><a href="https://localhost:9443">https://localhost:9443</a></p>
<p><a href="https://192.168.0.100:9443">https://192.168.0.100:9443</a></p>
</p>
</section>
</main>
<footer>
<hr/>
<p>Written by <a href="https://aney.co.uk" target="_blank" rel="noopener">@aney</a> with <a href="https://danluu.com/web-bloat/" target="_blank" rel="noopener">web bloat</a> in mind | <a href="https://github.com/Aney/website" target="_blank" rel="noopener">Source Code</a></p>
</footer>
</body>
</html>