Login

Navigation

This articles is published 635 days ago and last updated 590 days ago, some information may be out of date.

Alpine Linux based LXC with Docker support on a PVE host .png

Setting up an Alpine Linux-based Container (LXC) with Docker support on a Proxmox Virtual Environment (PVE) host.
Advantages
  • Lightweight and secure: Alpine Linux is a lightweight and secure distribution of Linux that is ideal for use in containers. It has a small footprint and is designed to minimize attack surface, making it a good choice for running Docker containers.
  • Flexibility: Using an LXC container allows you to run multiple instances of Docker on a single host, each with its own isolated environment and resources.
  • Easy management: Proxmox VE provides a user-friendly web interface for managing LXC containers, making it easy to start, stop, and configure containers.
  • Resource efficiency: Running Docker inside an LXC container allows you to maximize resource usage by sharing resources across multiple containers. This can lead to better performance and reduced resource usage compared to running Docker directly on the host.
  • Modularity: Using Docker allows you to easily manage and deploy applications in a modular way, with each container running a specific service or application. This can simplify the management and maintenance of complex systems.

Procedure
PVE Host Setting:

Create a new LXC container with the specified configuration:

pct create 302 volume01:vztmpl/alpine-3.17-default_20221129_amd64.tar.xz \
  --storage volume01 --rootfs volume=volume01:8 \
  --ostype alpine --arch amd64 --password P@ssw0rd --unprivileged 0 \
  --cores 2 --memory 1024 --swap 0 \
  --hostname lxc-alpine \
  --net0 name=eth0,bridge=vmbr0,ip=dhcp,firewall=1,type=veth \
  --start false
Configuration OptionValue
Container ID302
TemplateAlpine Linux
Storagevolume01
Root Filesystem Sizevolume=volume01:8
Operating System TypeAlpine
Architectureamd64
PasswordP@ssw0rd
Container Privileges0 means the container with privileged mode enabled
CPU Cores2
Memory1024
Swap0
Hostnamelxc-alpine
Network Settingsname=eth0,bridge=vmbr0,ip=dhcp,firewall=1,type=veth

Configure the LXC container to use an unconfined AppArmor profile and drop no capabilities:

cat >> /etc/pve/lxc/302.conf << EOF
lxc.apparmor.profile: unconfined
lxc.cap.drop:
EOF
ActionCommand
Container config file Location/etc/pve/lxc/302.conf
lxc.apparmor.profile: unconfinedDisabling AppArmor confinement
lxc.cap.drop:Retaining all capabilities for the container.

Start the LXC container:

pct start 302

LXC Container Setting:

Update and upgrade the container's package repositories and installed packages:

apk update && apk upgrade

This command updates the Alpine package repositories and upgrades the installed packages to their latest versions.

Install Docker and Docker Compose:

apk add docker docker-compose

This command installs Docker and Docker Compose, which are used to manage and deploy containerized applications.

Start the Docker service and enable it to start automatically on boot:

rc-service docker start
rc-update add docker

These commands start the Docker service and configure it to start automatically when the container boots.

Create the Docker configuration directory:

mkdir -p /etc/docker

Configure the Docker daemon with custom log and storage settings:

cat > /etc/docker/daemon.json << EOF
{
 "log-driver": "json-file",
 "log-opts": {
     "max-size": "20m",
     "max-file": "3"
 },
 "storage-driver": "vfs"
}
EOF
ParameterValue
File Location/etc/docker/daemon.json
Logging Driverjson-file
Logging Driver Optionsmax-size: 20m, max-file: 3
Storage Drivervfs

Restart the Docker service to apply the configuration changes:

rc-service docker restart

Conclusion
Setting up an Alpine Linux-based Container (LXC) with Docker support on a Proxmox Virtual Environment (PVE) host provides a secure, flexible, and efficient way to run Docker containers.

Reference

Related

There're 1 comments