CoreOS and Docker setup on VMware Fusion

Home » Computer Articles » Linux » CoreOS and Docker setup on VMware Fusion
December 22, 2014 Linux No Comments

Wanted to play around with Docker and found an interesting Operating System that hosts docker containers.

This is what I had to do to get it up and running on my Mac OS X with VMware Fusion.

 

 

Lets start by downloading CoreOS. Lightweight Cluster Server.

I downloaded the stable branch, you could also try alpha or beta.

# curl -LO http://stable.release.core-os.net/amd64-usr/current/coreos_production_vmware_insecure.zip

 

 

Unzip a couple of virtuals.

# unzip coreos_production_vmware_insecure.zip -d coreos1

# unzip coreos_production_vmware_insecure.zip -d coreos2 

 

 

Start VMware Fusion and open vmx file on coreos1 and then coreos2. I liked to add more memory, say 2G memory and 20G of disk space.

 

 

Start virtual server.

On the Mac open a terminal and cd into coreos1. Of course you will see I am using a private network for this test and also you should be setting up your own ssh keys.

 

$ cd coreos1

ssh -i insecure_ssh_key [email protected] hit enter. You should be logged into coreos1.

 

Now we need to setup a Cloud-Config. Now there is different ways to do this. I choose to setup the virtuals by editing each one, as I wanted to set a static ip address, start some services and connect to get the token for the cluster I want to setup.

 

OK, lets get the token for this new cluster. In a web browser go to http://discovery.etcd.io/new and copy and paste the result into a document, for later use.

 

Setup the Network

cd /etc/systemd/network

 

vi static.network

[Match]
Name=<interface Name>

[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8

 

Restart network

systemctl restart systemd-networkd

 

 

Now we will setup the Cloud-Config

# mkdir /var/lib/coreos-install

 

# vi /var/lib/coreos-install/user_data

#cloud-config
hostname: coreos1
coreos:
  etcd:
    discovery: https://discovery.etcd.io/<token>
    addr: 192.168.1.100:4001
    peer-addr: 192.168.1.100:7001
  update:
      reboot-strategy: etcd-lock
  units:
    - name: etcd.service
      command: start
    - name: fleet.service
      command: start

# coreos-cloudinit --from-file /var/lib/coreos-install/user_data

# cd /etc/systemd/system/

# mkdir etcd.service.d

# mv /run/systemd/system/etcd.service.d/20-cloudinit.conf /etc/systemd/system/etcd.service.d/20-cloudinit.conf

Restart virtual.

reboot

 

 

Now lets work on the second server.

$ cd coreos2

ssh -i insecure_ssh_key [email protected] hit enter. You should be logged into coreos2.

 

Now we need to setup a Cloud-Config. Now there is different ways to do this. I choose to setup the virtuals by editing each one, as I wanted to set a static ip address, start some services and connect to get the token for the cluster I want to setup.

 

OK, lets use the token we retrieved before.

 

Setup the Network

cd /etc/systemd/network

 

vi static.network

[Match]
Name=<interface Name>

[Network]
Address=192.168.1.101/24
Gateway=192.168.1.1
DNS=8.8.8.8

 

Restart network

systemctl restart systemd-networkd

 

 

Now we will setup the Cloud-Config

# mkdir /var/lib/coreos-install

 

# vi /var/lib/coreos-install/user_data

#cloud-config
hostname: coreos2
coreos:
  etcd:
    discovery: https://discovery.etcd.io/<token>
    addr: 192.168.1.101:4001
    peer-addr: 192.168.1.101:7001
  update:
      reboot-strategy: etcd-lock
  units:
    - name: etcd.service
      command: start
    - name: fleet.service
      command: start

 

# coreos-cloudinit --from-file /var/lib/coreos-install/user_data

# cd /etc/systemd/system/

# mkdir etcd.service.d

# mv /run/systemd/system/etcd.service.d/20-cloudinit.conf /etc/systemd/system/etcd.service.d/20-cloudinit.conf

 

Restart virtual.

reboot

 

Now we can check and see if the two servers are connected in a cluster.

fleetctl list-machines

You should receive something like this.

MACHINE IP METADATA
69bb93bb... 192.168.1.101 -
9d7c5291... 192.168.1.100 -

 

How to replace your ssh keys.

# cat ~/.ssh/id_rsa.pub | ssh [email protected] -i insecure_ssh_key update-ssh-keys -a user ssh [email protected] update-ssh-keys -D oem

Troubleshooting steps:
Fleet status.
# systemctl status -l fleet
Start Fleet.
# systemctl start fleet
Fleet status again. Should see it is running.
# systemctl status -l fleet
Now you should see the other hosts.
# systemctl list-machines

 

Now you can start playing around with Docker.

Login to one of your CoreOS servers and try the commands below.

 

This will download CentOS image.

# docker pull centos

Look at what images you have.

# docker images

Run a CentOS container Repository and connect to bash prompt.

# docker run -i -t centos /bin/bash

Run a CentOS 6 container, Repository:TAG and connect to bash prompt.

# docker run -i -t centos:centos6 /bin/bash

Run a CentOS 7 container, Repository:TAG and connect to bash prompt.

# docker run -i -t centos:centos7 /bin/bash

Look for the image you were working on.

# docker ps -a

Save to your image.

# docker commit 9dbb15de0aac coreos/apache

Login to your new image.

# docker run -i -t coreos/apache /bin/bash

Login to your new image.

# docker run -i -t coreos/apache:latest /bin/bash

If you update again you will need to save the image again.

 

Run a web server on port 80. You will connect by the server coreos1 or coreos2 apache is running on.

# docker run -d -p 80:80 apache /usr/sbin/apachectl -D FOREGROUND

Go to web browser and type in 192.168.1.100 or 192.168.1.101 and you should see the default web server.

 

 

There is a lot more you can do, this is just the beginning. I will be adding other articles about docker later.

 

 

References:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-coreos-cluster-on-digitalocean 

https://coreos.com/docs/quickstart/

https://coreos.com/docs/cluster-management/setup/cloudinit-cloud-config/

https://coreos.com/docs/launching-containers/building/getting-started-with-docker/

http://docs.docker.com/userguide/dockerizing/

https://docs.docker.com/installation/centos/

 

Ansible and Docker

http://www.ansible.com/home

http://www.ansible.com/docker

 

Docker Filesystem Persistence With Flocker

http://www.centurylinklabs.com/docker-filesystem-persistence-with-flocker/

 

Persistence Storage for MySQL Database.

http://www.alexecollins.com/content/docker-persistence/

http://txt.fliglio.com/2013/11/creating-a-mysql-docker-container/

 

CLI reference.

http://docs.docker.com/reference/commandline/cli/

 

Other reference stuff.

https://docs.docker.com/articles/basics/#check-your-docker-install

https://github.com/coreos/bugs/issues/100

https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-common-issues-with-your-coreos-servers

https://github.com/coreos/coreos-cloudinit/blob/master/Documentation/config-drive.md

http://seanmcgary.com/posts/deploying-docker-containers-on-coreos-using-fleet

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.