Definite's Extractor

My findings on Life, Linux, Open Source, and so on.

Chewable Fedora Atomic

Fedora Atomic is an operating system targets to containers. However, the documentation, for me, is very hard to read. In this document, I will share my adventure with Fedora Atomic, starting with post installation.

I have installed Fedora Atomic, now what?

Let’s say you want to install the tree and docker-compose for better understanding the directory structure of your new host; you also need to ping a host every hour; and of course, you want your shiny new docker application to be deploy to this machine.

Package Install with rpm-ostree


Atomic Host has neither yum nor dnf, it has rpm-ostree. It is not just the name change, it changes the behavior.
For example, for typical Fedora, tree can be run immediately after install the package tree, but with Atomic, after run:

sudo rpm-ostree -y install tree docker-compose

you have to reboot to use them, as rpm-ostree just install them “off-line”.

Note that I have also installed docker-compose. For some reason, docker-compose is not installed by default in Atomic Host. I expected I will encounter many projects that use docker-compose.

Schedule Command with systemd.timer

Another gotcha is crontab cannot be installed. Fortunately, you can use systemd.timer instead.

For pinging a host for every 1 hours, you need two files:

  • /etc/systemd/system/example.service
    [Service]
    # oneshot as ping -c 4 will exit automatically
    Type=oneshot
    # Actual command to run
    ExecStart=/sbin/ping -c 4 some.host.com
    
    [Install]
    # Run in multi-user mode when enabled
    WantedBy=multi-user.target
  • /etc/systemd/system/example.timer
    [Unit]
    
    [Timer]
    # Run 15 minutes after boot
    OnBootSec=15min
    # Every hour after last activated
    OnUnitActiveSec=1h
    
    [Install]
    # Run in multi-user mode when enabled
    WantedBy=multi-user.target

Enable the service and timer, then start the service and timer:

sudo systemctl enable example.service
sudo systemctl enable example.timer
sudo systemctl start example.service
sudo systemctl start example.timer

“Atomize” your Dockerfile

You CAN use it as typical docker, no problem. But do you really want to ask your users and yourself to type all the commands in the lengthy installation instructions?

Atomic smooth the experience by integrating the installation instructions in Dockerfile. I have a living example, Dockerfile of zanata-sinopia-docker-file, a dockerize npm repository server.

Look the line LABEL INSTALL=, basically it achieves two goals:

  1. Copy the required files from the container to host’s /tmp : this is done with docker privileged mode.
  2. Rest of the installation instructions on host: Especially with the tasks that required root of the host.

You can write the similar for your uninstall instructions (LABEL UNINSTALL) and run instructions (LABEL RUN).

After you done with development:

  1. At your development box, docker push your images.
  2. At the Atomic Host, to install the image, run:
    atomic install [repo]/[image]
  3. At the Atomic Host, to run the container:
    atomic run [repo]/[image]

That is it.

One response to “Chewable Fedora Atomic

  1. Pingback: Links 30/8/2017: New Stable Kernels, Paper on Security Record of Free Software | Techrights

Leave a comment