Skip to content

Docker Secrets

Justin J. Novack edited this page Oct 27, 2019 · 1 revision

Generate an SSH Key

# ssh-keygen -t rsa -b 4096 -C "autossh" -f autossh_id_rsa

Put the Key into Docker Secrets

# cat autossh_id_rsa | docker secret create autossh_id_rsa -

Copy the Key to the Remote Host

# ssh-copy-id -i autossh_id_rsa [email protected]

Deploy your Service

docker-compose-swarm.yml

version: '3.7'

services:
  service:
    image: jnovack/autossh:latest
    environment:
      - SSH_KEY_FILE=/run/secrets/autossh_id_rsa
      - SSH_HOSTUSER=username
      - SSH_HOSTNAME=203.0.113.10
      - SSH_TUNNEL_REMOTE=2222
      - SSH_TUNNEL_HOST=172.17.0.1
      - SSH_TUNNEL_LOCAL=22
      - TERM=xterm
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.role == manager
      restart_policy:
        condition: any
    secrets:
      - autossh_id_rsa

secrets:
  autossh_id_rsa:
    external: true
# docker stack deploy -c docker-compose-swarm.yml autossh
Clone this wiki locally