You can use the provided docker-compose.yml to orchestrate a swtpm instance and a test client. The setup uses a shared volume tpm-data to persist TPM state and a dedicated network swtpm for communication.
Service Configuration
swtpm service
This service runs the TPM simulator in socket mode. Key configurations include:
- Command arguments:
--tpm2: Enables TPM 2.0 support.--server type=unixio,path=/swtpm/swtpm.sock: Configures the server to use a Unix domain socket at /swtpm/swtpm.sock.--ctrl type=unixio,path=/swtpm/swtpm.sock.ctrl: Configures the control socket at /swtpm/swtpm.sock.ctrl.--tpmstate dir=/swtpm: Sets the directory for TPM state persistence.--log file=swtpm.log and --log level=20: Configures logging.--flags not-need-init,startup-clear: Sets specific TPM startup flags.
- Volumes: Mounts
tpm-data to /swtpm to ensure state persistence.
swtpm-test service
This service acts as a client to verify the TPM functionality. It depends on the swtpm service being ready.
- Environment Variables:
TPM2TOOLS_TCTI: Set to swtpm:path=/swtpm/swtpm.sock to instruct TPM2 tools to communicate with the simulator via the Unix socket.
- Command: Runs
tpm2 clear to test the TPM interface.
services:
swtpm:
build:
context: .
volumes:
- tpm-data:/swtpm
networks:
- swtpm
command: ['socket', '--tpm2',
'--server', 'type=unixio,path=/swtpm/swtpm.sock',
'--ctrl', 'type=unixio,path=/swtpm/swtpm.sock.ctrl',
'--tpmstate', 'dir=/swtpm',
'--log', 'file=swtpm.log',
'--log', 'level=20',
'--flags', 'not-need-init,startup-clear']
swtpm-test:
image: docker.io/strongx509/tpm:5.9.13
depends_on:
- swtpm
volumes:
- tpm-data:/swtpm
networks:
- swtpm
environment:
TPM2TOOLS_TCTI: swtpm:path=/swtpm/swtpm.sock
command: ['tpm2', 'clear']
volumes:
tpm-data:
networks:
swtpm: