This guide provides an Ansible playbook to deploy noVNC with Docker Compose.
noVNC is a VNC client only - a complete deployment requires:
Note: There is no official noVNC Docker image. This playbook uses community images.
- name: Deploy noVNC Stack
hosts: novnc
become: true
vars:
app_root: /opt/novnc
novnc_port: 6081
vnc_port: 5901
vnc_password: "{{ vault_novnc_vnc_password }}"
tasks:
- name: Install Docker on Debian/Ubuntu
apt:
name:
- docker.io
- docker-compose-plugin
state: present
update_cache: true
when: ansible_os_family == "Debian"
- name: Install Docker on RHEL family
dnf:
name:
- docker
- docker-compose-plugin
state: present
when: ansible_os_family == "RedHat"
- name: Enable and start Docker
service:
name: docker
state: started
enabled: true
- name: Create application directory
file:
path: "{{ app_root }}"
state: directory
mode: "0755"
- name: Create config directories
file:
path: "{{ item }}"
state: directory
mode: "0750"
loop:
- "{{ app_root }}/config"
- "{{ app_root }}/vnc-config"
- name: Write Docker Compose file
copy:
dest: "{{ app_root }}/docker-compose.yml"
mode: "0644"
content: |
services:
novnc:
image: lscr.io/linuxserver/novnc:latest
container_name: novnc
environment:
- PUID=1000
- PGID=1000
- RESOLUTION=1920x1080
volumes:
- ./config:/config
ports:
- "{{ novnc_port }}:80"
depends_on:
- vnc-server
restart: unless-stopped
vnc-server:
image: lscr.io/linuxserver/baseimage-kasmvnc:ubuntu-jammy
container_name: vnc-server
environment:
- PUID=1000
- PGID=1000
- SUBFOLDER=/
- KASMVNC_PASSWORD={{ vnc_password }}
volumes:
- ./vnc-config:/config
ports:
- "{{ vnc_port }}:5901"
restart: unless-stopped
- name: Start noVNC stack
command: docker compose up -d
args:
chdir: "{{ app_root }}"
- name: Wait for noVNC to be ready
wait_for:
port: "{{ novnc_port }}"
delay: 5
timeout: 60
vault_novnc_vnc_password) for security.Generate a secure VNC password before running the playbook:
# Generate secure password
openssl rand -base64 32
# Store in Ansible Vault
ansible-vault encrypt_string 'your-secure-password' --name 'vault_novnc_vnc_password'
http://YOUR-SERVER:6081vnc-server (Docker service name)5901To connect to an existing VNC server, modify the playbook to only deploy noVNC:
services:
novnc:
image: lscr.io/linuxserver/novnc:latest
ports:
- "6081:80"
Then configure the connection via the noVNC web UI with your external VNC server details.