Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
113 lines (73 sloc) 5.55 KB

Codefresh | Docs

Use Codefresh to Build and Deploy Containers to Microsoft Azure | ACS Engine or DockerCE via ACS

Before we begin

This document will walk you through deploying to a Docker Swarm Mode Cluster on Microsoft Azure using Azure Container Engine.

The method outlined in this document will also work for deployment to a DockerCE cluster on Azure Container Service. However, DockerCE clusters on ACS are currently in preview and are not recommended for production environments.

Part of this quickstart requires Azure CLI version 2.0.4 or later. From command line, run az --version to find the version. If you need to install or upgrade, see Install Azure CLI 2.0

Note: If you are looking for documentation on how to deploy to Azure Container Service using Swarm as your Orchestrator, 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.

Getting started

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.

Try this example locally

Just head over to the example repository in Github.

To run the provided example on a Docker Swarm from your local command line,

  1. First, open an SSH Tunnel to your Swarm Master and export an environment variable for DOCKER_HOST.
  • ssh -fNL 2375:localhost:2375 -p 2200
  • export DOCKER_HOST=:2375
  1. Second, make sure you have a swarm. If you don't, run:
  • docker swarm init

Note: If you used the 101 ACS Swarm Mode GitHub QuickStart Template or a DockerCE Cluster (preview) on Azure Container Service, your swarm is already initialized.

Once you have your swarm, in your cloned directory run:

  • docker stack deploy --compose-file docker-stack.yml vote

Deploy to Remote Swarm with codefresh.yml

  image: ncodefresh/remote-docker:azure
  working_directory: ${{main_clone}}
    - rdocker ${{RDOCKER_HOST}} docker stack deploy --compose-file docker-stack.yml ${{STACK_NAME}}
    - SSH_KEY=${{SSH_KEY}}
    - SSH_PORT=${{SSH_PORT}}

RDOCKER_HOST remote Docker swarm master machine, accessible over SSH (for example,

STACK_NAME is new Docker stack name (use "vote", for example)

SSH_KEY private SSH key, used to access Docker swarm master machine

SPLIT_CHAR split character, you've used to replace newline in SSH key. Recommendation: use , (comma character).

SSH_PORT is port 2200 (default SSH Port for ACS Engine and Azure Container Service with Swarm / DockerCE orchestrator)

LOCAL_PORT is port 2375 (port Docker Swarm-mode cluster is listening on)

The app will be running at the FQDN of the swarm agent pool on port 80 and the results will be accessible at port 8080. Examples:

Vote App: Results:

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). To quickly access the FQDN for both your Master and Agent load balancers, run the following command from your local command line:

az acs list --resource-group myResourceGroup --query '[*].{Master:masterProfile.fqdn,Agent:agentPoolProfiles[0].fqdn}' -o table


Master                                                               Agent
-------------------------------------------------------------------  --------------------------------------------------------------------

Note: You can also use the -g switch in place of --resource-group

Passing SSH key through ENV variable

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' ',')
  1. 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:azure to your Codefresh.yml file as provided in the example above.

  1. As a deploy command use rdocker ${{RDOCKER_HOST}} docker stack deploy --compose-file docker-stack.yml ${{STACK_NAME}} .

  2. Make sure you define the following variables in the pipeline as defined in the previous part:

    • SSH_KEY
    • SSH_PORT

Notice: The UI deploy step will run on any build. Make sure that your automated builds run only on a specific branch trigger.