This document will walk you through deploying to Azure Container Service using Swarm (pre version 1.12) as your Orchestrator, which does not support Docker stack at this time.
Note: If you are looking for documentation on how to deploy to a Docker Swarm Mode Cluster on Microsoft Azure using Azure Container Engine or a DockerCE cluster on Azure Container Service, please see this document instead. To learn more about the differences in Azure Container Service Docker Swarm and Docker Swarm Mode with ACS Engine, check out Microsoft's FAQ.
Download Docker. If you are on Mac or Windows, Docker Compose will be automatically installed. On Linux, make sure you have the latest version of Compose.
- First, open an SSH Tunnel to your Swarm Master and export an environment variable for DOCKER_HOST.
ssh -fNL 2375:localhost:2375 -p 2200 azureuser@azure.westcentralus.cloudapp.azure.comexport DOCKER_HOST=:2375
- Second, make sure you have a swarm. If you don't, run:
docker swarm init
Note: If you used Azure Container Service using Swarm as your Orchestrator, your swarm is already initialized.
Once you have your swarm, in this directory run:
docker run -d --name Demo -p 80:80 nginx
deploy_to_swarm:
image: ncodefresh/remote-docker:azure
working_directory: ${{main_clone}}
commands:
-rdocker ${{RDOCKER_HOST}} ${{LOCAL_PORT}} docker run -d --name ${{CONTAINER_NAME}} -p 80:80 ${{IMAGE_NAME}}
environment:
- SSH_KEY=${{SSH_KEY}}
- SSH_PORT=${{SSH_PORT}}
RDOCKER_HOST remote Docker swarm master machine, accessible over SSH (for example, azureuser@azure.southcentralus.cloudapp.azure.com)
LOCAL_PORT is port 2375 - the port your Docker Swarm Cluster is listening on
CONTAINER_NAME is new Docker container name (use "demo", for example)
IMAGE_NAME is the Docker image name (use "nginx", for example)
SSH_KEY private SSH key, used to access Docker swarm master machine
SPLIT_CHAR split character, you've used to replace
newlinein SSH key. Recommendation: use,(commacharacter)
SSH_PORT is port 2200 (default SSH Port for ACS Engine and Azure Container Service with Swarm / DockerCE orchestrator)
Note: Ports 80, 443, and 8080 are open by default on your Agent Load Balancer in Azure when using ACS Swarm, ACS Engine, or ACS with DockerCE (Preview)
Currently in order to pass SSH key through Codefresh UI, you need to convert it to single line string (replacing newline with comma), like this:
$ SSH_KEY=$(cat ~/.ssh/my_ssh_key_file | tr 'n' ',')
- Select Codefresh's Deploy Images in the pipeline's and select
ncodefresh/remote-docker:azure. Be sure to use the ssh-tunnel branch.
Note: You can also add
ncodefresh/remote-docker:azureto your Codefresh.yml file as provided in the example above.
-
As a deploy command use
rdocker ${{RDOCKER_HOST}} ${{LOCAL_PORT}} docker run -d --name ${{CONTAINER_NAME}} -p 80:80 ${{IMAGE_NAME}}. -
Make sure you define the following variables in the pipeline as defined in the previous part:
CONTAINER_NAMEIMAGE_NAMERDOCKER_HOSTSSH_KEYSPLIT_CHARSSH_PORTLOCAL_PORT
Notice: The UI deploy step will run on any build. Make sure that your automated builds run only on a specific branch trigger.