To successfully install Docker inside an LXC container running Ubuntu, with the host system being Debian, you’ll need to follow a series of steps to ensure both your container and host are properly configured to allow Docker to run within LXC. Here’s a comprehensive guide:
1. Prepare the Host System
For the Debian host, make sure your LXC is up to date:
sudo apt update
sudo apt upgrade
sudo apt install lxc
2. Configure LXC Container for Docker
When running Docker inside an LXC container, you might need to adjust the container’s configuration to allow it to use Docker-specific capabilities.
-
Create or Modify the LXC Container Configuration: You’ll need to edit the LXC container configuration file, usually located at /var/lib/lxc/<container-name>/config. Add the following lines to the file:
lxc.apparmor.profile = unconfined
lxc.cgroup.devices.allow = a
lxc.cap.drop =
lxc.arch = linux64
# These capabilities are necessary for Docker:
lxc.cap.keep = sys_admin, mac_admin, dac_override, setgid, setuid, net_admin, net_bind_service
This configuration allows the necessary capabilities Docker requires to run inside the container. Ensure to replace <container-name> with the actual name of your container.
Note: Editing your LXC container configuration to add these capabilities and setting the AppArmor profile to unconfined reduces the security isolation of the container, which might not be suitable in all environments.
3. Install Docker Inside the LXC Container
With your container configured, start the container and attach to it:
lxc-start -n <container-name>
lxc-attach -n <container-name>
Follow the steps to install Docker inside the container (as you would on a standard Ubuntu system):
-
Update Package Index:
apt update
-
Install Prerequisite Packages:
apt install apt-transport-https ca-certificates curl software-properties-common
-
Add Docker’s Official GPG Key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
-
Set up the Docker Repository:
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
-
Install Docker CE:
apt update
apt install docker-ce
-
Verify Docker Installation:
Run a test Docker command to ensure Docker is installed correctly inside your LXC container:
docker run hello-world
4. Troubleshooting
- If Docker fails to start within the LXC container, revisit the container configuration steps to ensure all necessary capabilities and permissions are properly set.
- Verify if AppArmor or another security module on the host or container is interfering with Docker.
Security Consideration
Running Docker inside an LXC container, especially with modified security constraints and capabilities, can introduce security risks. Ensure the environment is secured and isolated appropriately, particularly if used in production or exposed to the internet.
This process allows Docker to run inside an LXC container by adjusting container capabilities and security profiles. Still, it should be done with understanding the implications, particularly around security and isolation.