Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install docker and docker-compose on Azure using cloud-Init

Tags:

I wanted to bootstrap my Azure VM with Docker and Docker-compose using cloud-init. So far I tried something like below.

#cloud-config

package_update: true
package_upgrade: true

groups:
  - docker: [default]

runcmd:
  - [ sh, -c, "curl -sSL https://get.docker.com/ | sh" ]
  - [ sh, -c, "sudo curl -L "https://github.com/docker/compose/releases/download/$(git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | tail -n 1)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose" ]
  - [ sh, -c, "sudo chmod +x /usr/local/bin/docker-compose" ]

But it doesn't install the docker/ docker-compose and get below error

cloud-init[958]: 2019-02-28 00:51:02,447 - util.py[WARNING]: Failed loading yaml blob. Invalid format at line 11 column 32: "while scanning a plain scalar
[  333.241244] cloud-init[958]:   in "<unicode string>", line 11, column 32:
[  333.245521] cloud-init[958]:         - [ sh, -c, "sudo curl -L "https://github.com/docker/compos ...
2019/02/28 00:51:04.015216 INFO Daemon Wire protocol version:2012-11-30
[  333.245619] cloud-init[958]:                                    ^
[  333.259509] cloud-init[958]: found unexpected ':'
[  333.259584] 2019/02/28 00:51:04.019282 INFO Daemon Server preferred version:2015-04-05
cloud-init[958]:   in "<unicode string>", line 11, column 37:
[  333.474295] cloud-init[958]:         - [ sh, -c, "sudo curl -L "https://github.com/docker/compose/rel ...
[  333.514672] cloud-init[958]:                                         ^
[  333.554215] cloud-init[958]: Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details."
[  333.593764] cloud-init[958]: 2019/02/28 00:51:04.361760 INFO Daemon Waiting for ssh host key be generated at /etc/ssh/ssh_host_rsa_key.pub [1800 attempts remaining, sleeping 1s]
2019-02-28 00:51:02,470 - util.py[WARNING]: Failed loading yaml blob. Invalid format at line 11 column 32: "while scanning a plain scalar
[  333.705350] cloud-init[958]:   in "<unicode string>", line 11, column 32:
[  333.731074] cloud-init[958]:         - [ sh, -c, "sudo curl -L "https://github.com/docker/compos ...
[  333.769118] cloud-init[958]:                                    ^
[  333.789992] cloud-init[958]: found unexpected ':'
[  333.808855] cloud-init[958]:   in "<unicode string>", line 11, column 37:
[  333.831502] cloud-init[958]:         - [ sh, -c, "sudo curl -L "https://github.com/docker/compose/rel ...
[  333.863028] cloud-init[958]:                                         ^
[  333.885648] cloud-init[958]: Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details."
[  333.915174] cloud-init[958]: 2019-02-28 00:51:02,470 - util.py[WARNING]: Failed at merging in cloud config part from part-001

Apart from it I doubt how can I add Azure auto created default user (which was provided from UI) to docker group.

like image 419
SkyRar Avatar asked Feb 28 '19 01:02

SkyRar


People also ask

How do I run Docker compose in Azure pipeline?

Build service images (Required) Name of the Azure Service Connection. (Required) Name of the Azure Container Registry. (Required) Path to the primary Docker Compose file to use. (Optional) Additional Docker Compose files to be combined with the primary Docker Compose file.

Can we install Docker in Azure?

To deploy Docker containers on Azure, you must meet the following requirements: Download and install the latest version of Docker Desktop. Alternatively, install the Docker Compose CLI for Linux. Ensure you have an Azure subscription.

How do I install Docker on Azure Virtual Machine?

Download and install docker from the hub. At the end of the installation it asks you to log out and log in. Once you have logged in, wait for a minute to get the notification which asks you to enable hypervisor. Enable the hypervisor and wait for it to auto restart.


2 Answers

Just tested by myself on Azure using Ubuntu 18.04-LTS:

#cloud-config
package_upgrade: true

packages:
    - docker.io
    - docker-compose

# create the docker group
groups:
    - docker

# assign a VM's default user, which is mydefaultuser, to the docker group
users:
    - default
    - name: mydefaultuser
      groups: docker

runcmd can be left empty for this setup.

like image 93
devrogs Avatar answered Nov 01 '22 19:11

devrogs


you have " inside of other " which doesnt work without escaping. as for the user. I think default user created has id of 1000, you can just use that (probably test this hypothesis before).

like image 43
4c74356b41 Avatar answered Nov 01 '22 17:11

4c74356b41