Deploying to remote host
In addition to the common usage of Docker Compose where we copied the docker-compose.yml file along with some environmental arguments to the local machine, we can use remote host deployment. To install the server to additional hosts using this method we can log in into that additional machine and repeat the procedure. The disadvantage in this case is that for any change in the application version or Compose file, we have to copy, connect to the remote host and re-run.
There are 2 (better) methods to deploy the application to the remote host.
Using DOCKER_HOST environment variable to set up the remote host engine
DOCKER_HOST=“ssh://user@remotehost” docker-compose up -d
Using Docker contexts
Docker Contexts are an efficient way to automatically switch between different deployment targets.
To access the remote host more easily with the Docker client, we can create a context that will hold the connection path to it.
docker context create remote ‐‐docker "host=ssh://user@remotemachine"
Now, we can control everything from the local machine:
docker-compose ‐‐context remote up -d