Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon

Serving a Website from a LXD Container

Containers can serve many purposes, but one of the most common is serving websites. In this hands-on lab, we'll leverage everyday LXD commands to initialize a container, configure it to serve a website, and snapshot it so we can later deploy a cluster if desired.

Google Cloud Platform icon

Path Info

Clock icon Beginner
Clock icon 30m
Clock icon Apr 03, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create the Container

    Launch an Alpine Linux 3.18 container, called web01:

    lxc launch images:alpine/3.18 web01
  2. Challenge

    Configure nginx

    Access the container's shell:

    lxc exec web01 -- ash

    Update the container and install nginx:

    apk update
    apk add nginx

    Configure nginx to start at boot:

    rc-service nginx start && rc-update add nginx default

    Update the nginx configuration to serve content out of /var/www/hub at port 80:

    vi /etc/nginx/http.d/default.conf
    server {
            listen 80 default_server;
            listen [::]:80 default_server;
            root /var/www/hub/;

    Exit the container:

  3. Challenge

    Deploy the Website

    Push the website to the container:

    lxc file push hub/ web01/var/www/ --create-dirs -r

    Then restart nginx:

    lxc exec web01 -- rc-service nginx restart

    We can confirm this work by running curl against the private IP of our container:

    lxc list
    curl <container-ip-from-list>
  4. Challenge

    Snapshot the Container

    Take a snapshot of the web01 container:

    lxc snapshot web01 1.0
  5. Challenge

    Map Ports

    Ensure that when the host's IP is accessed, it forwards to the container:

    sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to <container_ip>:80

    To confirm visit the public IP of your provided server.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans