Skip to content

OCIO y TECnología

  • Privacy Policy
Offcanvas

  • Register
  • Lost your password ?

OCIO y TECnología

  • Home » 
  • Tecnología » 
  • Docker » 
  • Managing remote docker instances

Managing remote docker instances

Emilio González Montaña 2020/04/11 0

This is a short recipe to use new context feature in docker to create & switch between docker contexts, so you can run any docker command remotely without need to establish a SSH connection (it’s done automatically by the docker context).

Prerequisites

Docker version

You need a relative modern docker version, to check if your installed docker version supports it, just run:

$ docker context

Usage:	docker context COMMAND

Manage contexts

Commands:
  create      Create a context
  export      Export a context to a tar or kubeconfig file
  import      Import a context from a tar or zip file
  inspect     Display detailed information on one or more contexts
  ls          List contexts
  rm          Remove one or more contexts
  update      Update a context
  use         Set the current docker context

Run 'docker context COMMAND --help' for more information on a
command.

If all is OK you will see the help message, if not you will see an error message complaining about not existing docker command.

Public SSH key

You also need to send your public SSH key to the remote host, in order to allow a SSH connection from your local docker client to the remote docker server (replace user & IP):

$ ssh-copy-id emilio@192.168.1.18

You will need to accept the remote host key (if it’s the first time you connect to that server) and type the remote password.

Then you can try to log in without introducing the password:

$ ssh emilio@192.168.1.18

Creating & using docker contexts

Creating the context

To create a context, just run (we will call it eht, you can use the name you want):

$ docker context create eht --docker \
         "host=ssh://emilio@192.168.1.18"
eht
Successfully created context "eht"

Listing & switch contexts

The context is created (but not in use yet), you can list your contexts (including the default one pointing to local docker server) with this command:

$ docker context ls
NAME                DESCRIPTION                               DOCKER ENDPOINT               KUBERNETES ENDPOINT   ORCHESTRATOR
default *           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                         swarm
eht                                                           ssh://emilio@192.168.1.18                           

The selected context is marked with an asterisk after the context name.

To switch between context just run:

$ docker context use eht
eht
Current context is now "eht"

To check is working properly, run any docker command to check which docker server you are connected with, in my case I want to list the swarm nodes, because my selected docker context is the eht cluster:

$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
2tusd451dit99xa4rqakio7bk     docker-01           Ready               Active              Reachable           19.03.8
bjpao3x71d2vxfd0ale7yzvqg     docker-02           Ready               Active              Reachable           19.03.8
bimgyeacu85cdcc6h77vzqech     docker-03           Down                Drain                                   19.03.6
lgmhp6uq54mc52hhnqkvbbzt4 *   docker-04           Ready               Active              Leader              19.03.8
vvgq04cxfojaam59za35o6f7v     rasp-01             Ready               Active                                  19.03.8
9xd2s0e4lv4xese3yieol54d0     rasp-02             Ready               Active                                  19.03.8
iqyqky61f04uoh3na6e8qbm0c     rasp-03             Ready               Active                                  19.03.8
juwcoql2no9ilj6479wevn88m     rasp-04             Ready               Active                                  19.03.8

References

  • How to deploy on remote Docker hosts with docker-compose
  • Docker Context (official docker reference)
  • docker context (official docker command reference)

Comparte esto:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
Tags : Tags context   docker   SSH   ssh-key
Share
facebookShare on FacebooktwitterShare on TwitterpinterestShare on Pinterest
linkedinShare on LinkedinvkShare on VkredditShare on ReddittumblrShare on TumblrviadeoShare on ViadeobufferShare on BufferpocketShare on PocketwhatsappShare on WhatsappviberShare on ViberemailShare on EmailskypeShare on SkypediggShare on DiggmyspaceShare on MyspacebloggerShare on Blogger YahooMailShare on Yahoo mailtelegramShare on TelegramMessengerShare on Facebook Messenger gmailShare on GmailamazonShare on AmazonSMSShare on SMS
Post navigation
Previous post

Docker volume with NFS driver

Next post

bashtop – top on steroids on bash

Emilio González Montaña

Related Posts

Categories Data bases  Docker  Tecnología Managing remote docker instances

Recover corrupted Postgres DB WAL

Categories Docker  Linux  Tecnología  Utils Managing remote docker instances

Install WSL2 + Docker on Windows

Categories Docker  Tecnología  YAML Managing remote docker instances

Docker swarm Traefik reverse proxy

Leave a Comment Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Detachable screens to avoid SSH disconnections
  • Expose WSL2 port to the network
  • Rosaleda (parque El Retiro, Madrid)
  • Back to the painting table
  • Recover corrupted Postgres DB WAL

Categories

  • Aficiones
  • AI
  • Bricolage
  • Data bases
  • Docker
  • Escenografía
  • Eventos
  • Fotografía
  • Hardware
  • Linux
  • Networking
  • Partidas
  • Proxmox
  • Sin categoría
  • Tecnología
  • Utils
  • Viajes
  • Virtualization
  • Warhammer
  • YAML

Tags

anthill (1) apt (5) cellular-automatons (1) ceph (2) context (1) conways-life (1) cortador (1) debian (3) docker (9) docker-compose.yml (4) docker-swarm (5) DRY (1) El Imperio (2) Enanos (2) escenografía (3) fotos (3) GlusterFS (1) Guerreros del Caos (2) informática (1) Linux (8) M.2 (1) Mac (1) Madrid (2) maqueta (2) MariaDB (2) miniaturas (4) MySQL (2) NFS (2) NVMe (1) partida (2) poliestireno (1) portainer (1) proxmox (2) rocas (1) Sony A65 (2) SSH (5) ssh-key (1) Ubuntu (8) update (2) volume (1) Warhammer (11) Windows (3) WSL (2) WSL2 (2) YAML (1)

Archives

  • June 2024
  • May 2024
  • April 2024
  • February 2024
  • January 2024
  • September 2023
  • August 2023
  • June 2023
  • December 2021
  • April 2021
  • May 2020
  • April 2020
  • March 2020
  • November 2019
  • July 2018
  • February 2017
  • June 2015
  • April 2014
  • April 2011
  • January 2011
  • July 2010
  • June 2010
  • March 2010
  • November 2009
  • June 2009
  • December 2008
  • November 2008
  • October 2008
  • June 2008
  • May 2008
  • October 2007

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025 OCIO y TECnología - Powered by Nevothemes.
Offcanvas