<?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 Archives - Nerd Corner</title>
	<atom:link href="https://nerd-corner.com/tag/docker-en/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerd-corner.com/tag/docker-en/</link>
	<description>Craft your dreams!</description>
	<lastBuildDate>Sun, 16 Mar 2025 18:49:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://nerd-corner.com/wp-content/uploads/2019/10/cropped-LogoNerdCorner-2-32x32.png</url>
	<title>Docker Archives - Nerd Corner</title>
	<link>https://nerd-corner.com/tag/docker-en/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Deployment of a WebApp with Kubernetes and Caddy</title>
		<link>https://nerd-corner.com/deployment-of-a-webapp-with-kubernetes-and-caddy/</link>
					<comments>https://nerd-corner.com/deployment-of-a-webapp-with-kubernetes-and-caddy/#respond</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Sun, 16 Feb 2025 18:31:48 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[App development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[Caddy]]></category>
		<category><![CDATA[Caddy Server]]></category>
		<category><![CDATA[Cluster]]></category>
		<category><![CDATA[ClusterIP]]></category>
		<category><![CDATA[ConfigMap]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Domain]]></category>
		<category><![CDATA[Domain Registration]]></category>
		<category><![CDATA[Hetzner]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[Ingress]]></category>
		<category><![CDATA[Ingress Controller]]></category>
		<category><![CDATA[ip addres]]></category>
		<category><![CDATA[K3s]]></category>
		<category><![CDATA[Kubectl]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[LoadBalancer]]></category>
		<category><![CDATA[mySql]]></category>
		<category><![CDATA[Nest.js]]></category>
		<category><![CDATA[Node Port]]></category>
		<category><![CDATA[Pods]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[Reverse Proxy]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Service]]></category>
		<category><![CDATA[Step by step guide]]></category>
		<category><![CDATA[Traefik]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1695</guid>

					<description><![CDATA[<p>After describing how to create production-ready Docker images and upload them to Docker Hub in the last article, it is now time to make these &#8230; </p>
<p>The post <a href="https://nerd-corner.com/deployment-of-a-webapp-with-kubernetes-and-caddy/">Deployment of a WebApp with Kubernetes and Caddy</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>After describing how to create production-ready Docker images and upload them to Docker Hub in the last article, it is now time to make these images available on a server. The aim is to make the web application accessible to everyone via a dedicated domain. To do this, we use a virtual private server (VPS) from Hetzner and deploy Kubernetes (k3s) with Caddy as a reverse proxy.</p>
<p><strong><em>You might also be interested in this: </em></strong><a href="https://nerd-corner.com/create-docker-images-and-upload-them-to-docker-hub/"><em>Create Docker images and upload them to Dockerhub</em></a></p>
<h2>Set up a VPS with Hetzner</h2>
<p>Hetzner often offers referral links with credit benefits for new customers. Of course, you can also use other providers, but Hetzner is attractively priced and offers solid services.</p>
<h3>What is a VPS?</h3>
<p>A Virtual Private Server (VPS) is a virtual server that is operated on a physical machine and acts as an independent server. It offers more control than classic shared hosting and is a cost-effective alternative to dedicated servers. Access is usually via SSH (Secure Shell), which allows us to control the server via the command line.</p>
<h3>SSH access to the VPS</h3>
<p>Once a VPS has been created, it is usually managed via a secure shell (SSH). SSH is a protocol that enables encrypted connections to remote servers. The following command is used to connect to the server:</p>
<p data-start="1137" data-end="1384"><span style="background-color: #e9ebec; color: #222222; font-family: Monaco, Consolas, 'Andale Mono', 'DejaVu Sans Mono', monospace; font-size: 15px;">ssh root@&lt;IP-Server&gt;</span></p>
<p>If an SSH key has been stored, authentication can be carried out using public key authentication, which is more secure than a password.</p>
<h3>Create a server at Hetzner</h3>
<ol>
<li>After logging into the Hetzner Cloud, we navigate to “Projects” and create a new project.</li>
<li>Select “Add server” and can configure an instance.</li>
<li>The cheapest model is often sufficient to start with. However, I recommend activating the option for an IPv4 address, as purely IPv6-based setups often cause compatibility problems.</li>
</ol>
<h3>Setting up a domain</h3>
<p>To access the application later under your own domain, you must register a domain and link it to the server.</p>
<h3>Apply for a domain at Hetzner</h3>
<ol>
<li>Register a new domain or add an existing domain in the Hetzner ConsoleH.</li>
<li>To manage DNS entries, we need to activate DNS access.</li>
</ol>
<h3>Set name servers</h3>
<p>The following name servers should be used:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">helium.ns.hetzner.de. 
hydrogen.ns.hetzner.com. 
oxygen.ns.hetzner.com.</pre>
<p>These new name servers offer better performance and flexibility compared to the old Hetzner name servers:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">ns1.first-ns.de.
robotns2.second-ns.de.
robotns3.second-ns.com.</pre>
<p>However, both nameserver variants are possible! The DNS changes take some time. However, we can use tools such as MXToolbox to check whether the changes have already taken place.</p>
<h3>Connect the domain to the server</h3>
<p>Now the IP address of the server must be linked to the domain:</p>
<ol>
<li>Switch to DNS zones in the Hetzner Cloud.</li>
<li>Select the registered domain.</li>
<li>Create a new A-Record and enter the IPv4 address of the server.</li>
<li>If available, remove the IPv6 record (AAAA) to avoid compatibility problems.</li>
</ol>
<p>You can also use <a href="http://mxtoolbox.com">MXToolbox</a> to check whether the DNS changes have already been applied.</p>
<h2>Set up Kubernetes</h2>
<p>Kubernetes is a powerful orchestration tool for containers. I use k3s, a lean Kubernetes variant that is particularly suitable for smaller environments.</p>
<h3>Install K3s on the server</h3>
<p>Connect to the server via SSH and install k3s with the following command:</p>
<pre><code class="language-sh">curl -sfL https://get.k3s.io | sh - </code></pre>
<p>The script installs k3s and starts the Kubernetes service. After installation, k3s can be checked with the following command:</p>
<pre><code class="language-sh">kubectl get nodes
</code></pre>
<p>k3s comes with its own kubectl version, so that no separate installation is necessary.</p>
<h3>Create YAML files for FE, BE, MySQL and Redis</h3>
<p>To deploy our application, we need YAML files for:</p>
<ul>
<li>Frontend (Angular)</li>
<li>Backend (NestJS)</li>
<li>Database (MySQL)</li>
<li>Session-Management (Redis)</li>
</ul>
<p>A deployment file for the backend could look like this:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
        - name: backend
          image: dockerhub-user/backend:latest
          ports:
            - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: backend-service
spec:
  selector:
    app: backend
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  type: ClusterIP
</pre>
<h3>What are deployments and services?</h3>
<ul>
<li>Deployments manage the provision and scaling of containers.</li>
<li>Services ensure a stable network connection between containers.</li>
<li>ClusterIP means that the service is only accessible within the Kubernetes cluster.</li>
</ul>
<h3>Set up Caddy as a reverse proxy</h3>
<p>A reverse proxy is required to ensure that incoming traffic is distributed correctly. K3s comes with Traefik by default, but I opted for a simpler solution: Caddy. I was really surprised how little guidance or documentation there is on Caddy in combination with Kubernetes.</p>
<h3>Why Kubernetes with Caddy?</h3>
<ul>
<li>Automatic Let&#8217;s Encrypt SSL certificates</li>
<li>Simple configuration via Caddyfile</li>
<li>Built-in load balancer</li>
</ul>
<h3>Remove Traefik</h3>
<pre><code class="language-sh">kubectl delete helmrelease traefik -n kube-system
</code></pre>
<h3>Create Caddy Deployment</h3>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">apiVersion: apps/v1
kind: Deployment
metadata:
  name: caddy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: caddy
  template:
    metadata:
      labels:
        app: caddy
    spec:
      containers:
        - name: caddy
          image: caddy
          volumeMounts:
            - name: caddy-config
              mountPath: /etc/caddy/Caddyfile
      volumes:
        - name: caddy-config
          configMap:
            name: caddy-config
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: caddy-config
data:
  Caddyfile: |

    example.com {
        reverse_proxy backend-service:3000
    }

---
apiVersion: v1
kind: Service
metadata:
  name: caddy-service
spec:
  type: LoadBalancer
  selector:
    app: caddy
  ports:
    - port: 80
      targetPort: 80
    - port: 443
      targetPort: 443</pre>
<p>Important: Since Let&#8217;s Encrypt has a rate limit, tests should first be carried out with staging certificates!</p>
<h2>Conclusion</h2>
<p>After these steps, the application is now running in a Kubernetes cluster on a Hetzner VPS and can be accessed via its own domain. The next step would be to set up an automatic CI/CD pipeline to deploy new versions without manual effort.</p>
<p>The post <a href="https://nerd-corner.com/deployment-of-a-webapp-with-kubernetes-and-caddy/">Deployment of a WebApp with Kubernetes and Caddy</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/deployment-of-a-webapp-with-kubernetes-and-caddy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Create Docker images and upload them to Docker Hub</title>
		<link>https://nerd-corner.com/create-docker-images-and-upload-them-to-docker-hub/</link>
					<comments>https://nerd-corner.com/create-docker-images-and-upload-them-to-docker-hub/#respond</comments>
		
		<dc:creator><![CDATA[Nerds]]></dc:creator>
		<pubDate>Thu, 16 Jan 2025 18:16:16 +0000</pubDate>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[Backend]]></category>
		<category><![CDATA[Backend Server]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Docker Hub]]></category>
		<category><![CDATA[Docker Images]]></category>
		<category><![CDATA[Docker Repository]]></category>
		<category><![CDATA[frontend]]></category>
		<category><![CDATA[google cloud mysql]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[mySql]]></category>
		<category><![CDATA[Nest]]></category>
		<category><![CDATA[Nest.js]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[redis session management]]></category>
		<category><![CDATA[redis session management nest.js]]></category>
		<category><![CDATA[Repository]]></category>
		<category><![CDATA[Step by step guide]]></category>
		<guid isPermaLink="false">https://nerd-corner.com/de/?p=1691</guid>

					<description><![CDATA[<p>In this article, I will show you how to create production-ready Docker images for a web application with Angular, NestJS, MySQL and Redis and then &#8230; </p>
<p>The post <a href="https://nerd-corner.com/create-docker-images-and-upload-them-to-docker-hub/">Create Docker images and upload them to Docker Hub</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In this article, I will show you how to create production-ready Docker images for a web application with Angular, NestJS, MySQL and Redis and then publish them on Docker Hub. The prerequisite is an installed Docker environment.</p>
<p><em><strong>You might also be interested in this: </strong><a href="https://nerd-corner.com/lessons-learned-hosting-nestjs-app-on-vercel/">Hosting NestJS on Vercel</a></em></p>
<h2>Creation of the Docker Compose Yml</h2>
<p>With Docker Compose, all components of an application can be defined via a single configuration file and built or started together.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">version: '3.8'

services:
  frontend:
    build: ./frontend
    ports:
      - "80:80"
    depends_on:
      - backend

  backend:
    build: ./backend
    ports:
      - "3000:3000"
    depends_on:
      - mysql
      - redis
    environment:
      - DATABASE_URL=mysql://user:password@mysql:3306/db
      - SESSION_STORE=redis://redis:6379

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: db
    ports:
      - "3306:3306"

  redis:
    image: redis:latest
    ports:
      - "6379:6379"</pre>
<h2>Creating the env file</h2>
<p>To manage environment variables centrally, we create an .env file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">DATABASE_URL=mysql://user:password@mysql:3306/db 
SESSION_STORE=redis://redis:6379</pre>
<p>Important: All ENV variables used in the code must also appear in docker-compose.yml!</p>
<h2>Docker image for the frontend</h2>
<p>The Angular frontend must be built for production. Here is an example Dockerfile:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">FROM node:20 AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod

FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf</pre>
<p>Since we are dependent on nginx for the build, we also need a corresponding config file:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">server {
  listen 80;
  server_name _;

  location / {
    root /usr/share/nginx/html;
    index index.html;
    try_files $uri $uri/ /index.html;
  }
}</pre>
<h2>Docker image for the backend</h2>
<p>The NestJS backend also needs to be built. Here is an optimized Dockerfile.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic"># Build stage
FROM node:20 AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine
WORKDIR /app

COPY --from=build /app/dist ./dist
COPY package.json package-lock.json ./
RUN npm install --only=production
CMD ["node", "dist/main.js"]</pre>
<h2>Building the app with Docker Compose</h2>
<p>Once all the Dockerfiles have been configured, the images can now be built. The whole thing is really easy with Docker compose.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker compose up -d --build</pre>
<p>The images are then ready, the containers are built and the app can be tested locally! The last step is to upload the images to DockerHub so that they can be used more easily later for deployment on a server.</p>
<h2>Uploading to Docker Hub</h2>
<p>Uploading is explained step by step below:</p>
<ol>
<li>Create an account on <a href="https://www.docker.com/products/docker-hub/">Dockerhub</a></li>
<li>Create a repository for the frontend and backend (1 private repo is currently free)</li>
<li>Build the images and tag them:
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker tag &lt;image-id&gt; dockerAccountName/frontend:latest
docker tag &lt;image-id&gt; dockerAccountName/backend:latest</pre>
</li>
<li>Sign up and push the images:
<pre class="EnlighterJSRAW" data-enlighter-language="generic">docker login
docker push dockerAccountName/frontend:latest
docker push dockerAccountName/backend:latest</pre>
</li>
</ol>
<h2>Outlook: Deployment with Kubernetes</h2>
<p>Now that the images are on Docker Hub, nothing stands in the way of deployment. I have opted for a Kubernetes cluster on a Hetzner VPS. <a href="https://nerd-corner.com/deployment-of-a-webapp-with-kubernetes-and-caddy/">More information here</a>.</p>
<p>The post <a href="https://nerd-corner.com/create-docker-images-and-upload-them-to-docker-hub/">Create Docker images and upload them to Docker Hub</a> appeared first on <a href="https://nerd-corner.com">Nerd Corner</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://nerd-corner.com/create-docker-images-and-upload-them-to-docker-hub/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
