# Launch a RancherOS instance with cloud-init

**URL:** <https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390>\
**Category:** RancherOS\
**Created:** [September 3, 2015, 11:36am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390 "2015-09-03T11:36:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 3, 2015, 11:36am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/1 "2015-09-03T11:36:49Z")

</div>

When launching one of the RnacherOS AMIs, I would like to be able to use `cloud-init` to launch `rancher-server`. From experimenting with this, and having read the documentation, I’m not sure that it’s currently possible.

I’ve tred to use a `cloud-init` file which looks like this:

```auto
#cloud-config

runcmd:
 - docker run -d --restart=always -p 8080:8080 rancher/server

```

I wonder if anybody has any thoughts on this, particularly if there are any good reasons why I **shouldn’t** be trying to get this running!

---

<div class="post-metadata">

**Author:** ![imikushin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/imikushin/32/17_2.png) [@imikushin](https://forums.suse.com/u/imikushin)\
**Post date:** [September 4, 2015, 4:20am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/2 "2015-09-04T04:20:42Z")

</div>

Hi @philpowell,

Use the following cloud-config as your instance’s user data to start Rancher Server:

```auto
#cloud-config
rancher:
  services:
    rancher-server:
      image: rancher/server
      restart: always
      ports:
      - 8080:8080

```

Cheers!

---

<div class="post-metadata">

**Author:** ![imikushin](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/imikushin/32/17_2.png) [@imikushin](https://forums.suse.com/u/imikushin)\
**Post date:** [September 4, 2015, 4:47am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/3 "2015-09-04T04:47:55Z")

</div>

In fact, you can specify your services just using compose format (just use `#compose` as the header), like this:

```auto
#compose
rancher-server:
  image: rancher/server
  restart: always
  ports:
  - 8080:8080

```

---

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 4, 2015, 7:50am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/4 "2015-09-04T07:50:07Z")

</div>

Brilliant! Thank you. I will try this out later today.

---

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 8, 2015, 8:40am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/5 "2015-09-08T08:40:02Z")

</div>

I’m still getting tripped up by this a little, and I think I need to understand a bit more about how cloud-init is being initiated.

When I use the `#cloud-config` config, the EC2 instance starts up fine, but the cloud-init doesn’t appear to be initiated. There’s no sign of any unusual activity in `/var/log/docker.log`.

When I use the `#compose` config, it doesn’t appear to initiate, **and** I’m unable to access the instance through SSH (I install a key when the instance is fired up). The SSH connection is refused, so it seems as though this config is conflicting with the startup of the instance — it’s difficult for me to determine what’s happening though, when I’m unable to access the instance.

I’m wondering if I’m missing something glaringly obvious?

---

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 8, 2015, 9:11am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/6 "2015-09-08T09:11:11Z")

</div>

Actually, a correction: it looks as though the `#cloud-config` config is also preventing SSH from starting up. So I can only assume that the cloud-init is overriding any and all services which EC2 might have been starting by default. But Rancher still doesn’t look like it’s started up.

---

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 8, 2015, 12:10pm UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/7 "2015-09-08T12:10:14Z")

</div>

Well, it turns out that — as with most things in life — I simply wasn’t being patient enough! Both of those configuration methods worked: it just took a little longer for the instance to fire up it’s services than usual. I’m curious to know why that is, but I’m sure I can glean something from the logs.

Thanks for your help with this @imikushin

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [September 8, 2015, 5:28pm UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/8 "2015-09-08T17:28:22Z")

</div>

@philpowell It probably took some time as the rancher/server image needed to be downloaded from Docker and on to your host. At least that’s what my guess would be.

---

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 11, 2015, 8:58am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/9 "2015-09-11T08:58:02Z")

</div>

Yes, I hadn’t properly appreciated the amount of time it would take for the image to be pulled. I’m very happy that the server can be started as soon as the instance starts up though — we are now able to provision and start up a Rancher server with a single command.

---

<div class="post-metadata">

**Author:** ![treeder](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/treeder/32/243_2.png) [@treeder](https://forums.suse.com/u/treeder)\
**Post date:** [September 19, 2015, 5:09am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/10 "2015-09-19T05:09:13Z")

</div>

How could this pull from a private repo during cloud-init? Where would it look for the .dockercfg?

---

<div class="post-metadata">

**Author:** ![philpowell](https://avatars.discourse-cdn.com/v4/letter/p/b5ac83/32.png) [@philpowell](https://forums.suse.com/u/philpowell)\
**Post date:** [September 20, 2015, 8:13pm UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/11 "2015-09-20T20:13:20Z")

</div>

I guess if you wanted to pull a private image, you could provide a command in cloud-init to populate your `.dockercfg` with the appropriate credentials. I think you’d probably be looking at `runcmd` for that though, and I’m not 100% sure the Rancher flavour of cloud-init on the AMI supports that (it’s where I ran into trouble first time around).

---

<div class="post-metadata">

**Author:** ![whiteadam](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/whiteadam/32/493_2.png) [@whiteadam](https://forums.suse.com/u/whiteadam)\
**Post date:** [April 26, 2016, 8:47pm UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/12 "2016-04-26T20:47:06Z")

</div>

FYI for anyone who comes across this:

There is no runcmd subset of cloud-init in RancherOS (yet…) as far as I understand.

---

<div class="post-metadata">

**Author:** ![Shuliyey](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/shuliyey/32/495_2.png) [@Shuliyey](https://forums.suse.com/u/Shuliyey)\
**Post date:** [March 16, 2017, 1:15am UTC](https://forums.suse.com/t/launch-a-rancheros-instance-with-cloud-init/390/13 "2017-03-16T01:15:15Z")

</div>

**runcmd** is executed at the run level before the docker service is started.

Reference: **When using runcmd, RancherOS will wait for all commands to complete before starting Docker**

```auto
[rancher@ip-172-31-8-65 ~]$ sudo system-docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61cbe4279219 rancher/os-console:v0.8.0 "/usr/bin/ros entrypo" 3 weeks ago Up 3 weeks console
ef4b6a51a53b rancher/os-docker:1.12.6 "ros user-docker" 3 weeks ago Up 3 weeks docker
...

```

To run docker commands on system bootup, can create **/etc/rc.local** file, or other run level startup scripts

This is a good guide: [https://docs.rancher.com/os/configuration/running-commands/](https://docs.rancher.com/os/configuration/running-commands/)

The best way to do this is to define a rancher.services in the #cloud-init as suggested by @imikushin

just two month ago (as I’m writing this comment), rancher also introduced a new parameter **awslocal** to the **–advertise-address** parameter, hence you could start rancher in HA mode on startup, through defining rancher.services in #cloud-init

e.g.

```auto
#cloud-config
mounts:
  -
    - /dev/vdb
    - /mnt
    - ext4
    - ""

ssh_authorized_keys:
  - $key

rancher:
  services:
    rancher-server:
      image: rancher/server:stable
      restart: unless-stopped
      command:
        - --db-host
        - $mariadb_ip
        - --db-user
        - $cattle_user
        - --db-pass
        - $cattle_password
        - --db-name
        - $cattle_db
        - --advertise-address
        - awslocal
      ports:
        - 8080:8080
        - 9345:9345

```

This is the change that introduced **awslocal** [https://github.com/rancher/rancher/commit/9fb7750a1a9e83e8a49f58a92020f8b42941b5a5](https://github.com/rancher/rancher/commit/9fb7750a1a9e83e8a49f58a92020f8b42941b5a5)
