Compute Instances
The most obvious and trivial way to run a container on OCI is to create a compute instance, install a container runtime on that instance, and then use the tooling provided by the container runtime to create and manage containers. Although this is a perfectly valid model, it often involves more (and often unacceptable) management overhead for the developers because of the need to keep the container runtimes, tools, and other infrastructure components updated and patched on a rigorous schedule. However, this approach affords you the highest amount of control in managing your workloads.
The trivial method for booting a compute instance with a container runtime is to install it at first boot using cloud-init3. Listing 3-1 shows an example cloud-init configuration for Oracle Linux 7, to install Docker, enable the service, and start it. The example also adds the default opc user to the docker group so that this user can use the docker command without using sudo.
Listing 3-1 cloud-init Example for Bootstrapping an Oracle Linux 7 Instance with a Container Runtime
#cloud-config bootcmd: - [ cloud-init-per, once, enable-epel, yum-config-manager, --enable, ol7_ developer_epel] groups: - docker users: - default - name: opc groups: docker shell: /bin/bash sudo: ALL=(ALL) NOPASSWD:ALL packages: - docker-engine - docker-cli runcmd: - [ systemctl, daemon-reload ] - [ systemctl, enable, docker.service ] - [ systemctl, start, --no-block, docker.service ]
Oracle Linux 8 does not feature the Oracle Container Runtime for Docker and instead uses Podman, Buildah, and Skopeo, which is a set of container tools based on the Open Container Initiative. All the tools are available conveniently in a single module that can be installed with the following command:
sudo dnf module install container-tools:ol8
This command can be used from within the cloud-init configuration as well.
Aside from using cloud-init to set up required packages, you can also create custom OS images with the tools preinstalled. This approach avoids the installation process at instance creation time. It saves several seconds when launching an instance, which can be quite significant if you have highly performance-sensitive workloads that frequently need ephemeral compute instances. Several task-based workloads belong to this category. When using this approach, an instance is created and then the required packages and settings are configured. A custom OS image is created from this instance, which now includes the packages and customizations that were applied to the instance. New instances can thus be created using the custom image as the OS image.