Execute Docker commands on remote hosts via SSH, ideal for Docker Swarm deployments.
To use this image, you need to provide your SSH credentials and the Docker command you want to execute.
docker run -e SSH_USERNAME=user -e SSH_HOST=example.com betterweb/docker-socket-over-ssh <docker command>
Replace <docker command>
with the Docker command you want to execute on the remote host.
SSH_USERNAME
: The username for SSH authenticationSSH_HOST
: The hostname or IP address of the remote Docker hostSSH_PRIVATE_KEY
: The SSH private key as a string (optional)
You have three options to provide the SSH key:
-
As an environment variable:
docker run -e SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" -e SSH_USERNAME=user -e SSH_HOST=example.com betterweb/docker-socket-over-ssh <command>
-
As a Docker secret (in Swarm mode):
echo "$(cat ~/.ssh/id_rsa)" | docker secret create ssh_private_key - docker service create --secret ssh_private_key -e SSH_USERNAME=user -e SSH_HOST=example.com betterweb/docker-socket-over-ssh <command>
-
By mounting the key file:
docker run -v ~/.ssh/id_rsa:/root/.ssh/id_rsa:ro -e SSH_USERNAME=user -e SSH_HOST=example.com betterweb/docker-socket-over-ssh <command>
To deploy a service to a Docker Swarm, you might use a command like this:
docker run -e SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" \
-e SSH_USERNAME=swarm-manager \
-e SSH_HOST=swarm.example.com \
betterweb/docker-socket-over-ssh \
stack deploy -c docker-compose.yml my-stack
This command deploys a stack defined in docker-compose.yml
to the Swarm cluster.
- Always use secure methods to pass your SSH key
- Ensure your SSH keys have appropriate permissions (600 for private keys)
- Use strong, unique passwords for SSH accounts
- Consider using SSH key authentication instead of password authentication
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.