Container Instances
OCI Container Instances, API version 20210415 (SDK package containerinstances, client
ContainerInstanceClient, CLI oci container-instances). Each container instance runs for real
on Docker, so its containers serve traffic and write logs you can read back. Real OCI serves the
API on compute-containers.{region}.oci.{domain}; floci-oci serves it on port 4599 with the other
services.
Supported operations
| Area | Operations |
|---|---|
| Container instances | CreateContainerInstance, GetContainerInstance, ListContainerInstances, UpdateContainerInstance, DeleteContainerInstance, ChangeContainerInstanceCompartment |
| Runtime | StartContainerInstance, StopContainerInstance, RestartContainerInstance |
| Containers | GetContainer, ListContainers, UpdateContainer, RetrieveLogs |
| Catalog | ListContainerInstanceShapes |
| Work requests | GetWorkRequest, ListWorkRequests, ListWorkRequestErrors, ListWorkRequestLogs |
Every instance gets one VNIC on the subnet it names. Networking serves it on GetVnic and
UpdateVnic (see Networking), which is what the Terraform provider reads
back for oci_container_instances_container_instance.
How a container instance runs
- One pod per instance. A pause container (
registry.k8s.io/pause:3.10by default) holds the instance's network namespace on the shared Docker network, and each container joins it (--network container:<pause>), so the containers of one instance reach each other onlocalhost, as in OCI. - The VNIC address is the pod's address.
privateIpon the VNIC is the pause container's IP on its Docker network, recorded each time the pod starts, so other containers on that network (the compat suites, a client indocker compose) reachhttp://<privateIp>:<port>. A stopped and started instance can come back with another address, and the VNIC follows it. AprivateIpgiven on create is kept as sent, and nothing on Docker answers on it. On macOS, the host cannot reach container IPs; use a container on the same network. - Images. Each image is pulled before anything starts. An image pushed to the local
Container Registry (
<region-key>.ocir.localhost.floci.io/<namespace>/<repo>) is pulled from the registry sidecar.imagePullSecretsof typeBASIC(base64 username and password) andVAULT(a secret in this emulator's Vault holding{"username": ..., "password": ...}) are used for their registry. - Containers.
commandreplaces the image's entrypoint andargumentsits command, as the SDK describes them;environmentVariablesandworkingDirectorypass through.resourceConfig.vcpusLimitandmemoryLimitInGBsbecome Docker CPU and memory limits. - Security context. A container's
securityContext(LINUX) applies to its Docker container:runAsUserandrunAsGroupare the process user (runAsGroupneedsrunAsUser, as the SDK says, or the create is400 InvalidParameter),isRootFileSystemReadonlymakes/read-only, andcapabilities.dropCapabilitiesandaddCapabilitiesare dropped and added by Docker's names (CAP_NET_RAWisNET_RAW,ALLis all). WithisNonRootUserCheckEnabled, a container that would run as UID 0 (runAsUser: 0, or norunAsUserand an image without a non-rootUSER) fails the start: the instance isFAILEDwith the reason inlifecycleDetails, as the SDK describes. An imageUSERgiven by name counts as non-root unless it isroot(inferred: floci-oci does not read the image's passwd file). The instance'ssecurityContext.fsGroupis a supplementary group of every container. - DNS. The instance's
dnsConfiggoes on the pause container, whose/etc/resolv.confevery container of the pod shares:nameserversreplace floci-oci's embedded DNS (which stands in for the subnet's resolver when they are left out), andsearchesandoptionsare thesearchandoptionslines. - Volumes. Each volume of the instance is one named Docker volume, shared by every container
that mounts it and removed with the instance:
EMPTYDIRon disk, or on tmpfs forbackingStore: MEMORY;CONFIGFILEfilled with its files before any container starts, so they appear at<mountPath>/<path>/<fileName>. A mount withisReadOnly: trueis a read-only mount for every volume type. Volume names are case-sensitive:Cacheandcacheare two volumes.subPathis stored and returned but not applied. - File Storage volumes. floci-oci has no File Storage service, so an
OCI_FSS_FILE_SYSTEMvolume is emulated as one named Docker volume per tenancy and export OCID (export.id): every instance of the tenancy that mounts the same export shares its files, and the volume outlives the instances, as a file system does; only a state reset removes it. The mount target and export are taken by OCID as sent and not looked up (there is nothing to look them up in), so two exports of one file system are two separate volumes.securityandmountCommand(NFS options, in-transit encryption) are stored and returned and have no effect on a Docker volume;subnetId, when given, must exist in Networking. With the instance'ssecurityContext.fsGroup, the volume root is given to that group with the setgid bit andrw-rw----added to its permissions, as the SDK describes; only the root is changed, once per volume while floci-oci runs, sofsGroupChangePolicymakes no difference (inferred). - Work requests. Create, delete, start, stop and restart return a work request that finishes
when Docker has done the work; the instance is
CREATING(orUPDATING,DELETING) until then. A pull or start failure leaves the instanceFAILEDwith the error inlifecycleDetailsand onListWorkRequestErrors; so does a delete that Docker cannot finish (the instance keeps its VNIC and can be deleted again), and a stop or restart Docker rejects fails its work request the same way. A container or volume that is already gone does not count as a failure. Update and change compartment finish at once. - Graceful shutdown. Stop, restart, the restart policy and a shutdown of floci-oci give each
container
gracefulShutdownTimeoutInSecondsto exit before Docker kills it. Left out, it is0and the containers are killed at once (inferred: the SDK documents no default). - Restart policy. floci-oci checks the containers every five seconds. A container that
exited is restarted under
ALWAYS, and underON_FAILUREwhen its exit code is not zero, andcontainerRestartAttemptCountcounts it; otherwise it becomesINACTIVEwith itsexitCodeandtimeTerminated. An instance whose containers have all stopped becomesINACTIVE. The check of an instance runs in turn with that instance's stop, start, restart and delete (each instance has its own queue, so a slow image pull for one never delays another), and restarts a container only while its instance isACTIVEwith nothing pending, so it never undoes a stop. - Health checks. A container's
HTTPandTCPhealth checks (the only two types in the SDK) run from a helper container (busybox:1.36by default, seeFLOCI_OCI_SERVICES_CONTAINERINSTANCES_HELPER_IMAGE) that shares the pod's network namespace, started only for an instance that has health checks.HTTPis a GET ofhttp://localhost:<port><path>with the check'sheaders, healthy on a 2xx or 3xx answer;TCPis a connect tolocalhost:<port>; each gives up aftertimeoutInSeconds. A check runs once the container has been up forinitialDelayInSeconds, then everyintervalInSeconds, on the five-second check above (so an interval under five seconds acts as five). ItsstatusisUNKNOWNuntil the first run,HEALTHYafter the first success, andUNHEALTHYafterfailureThresholdconsecutive failures, with the failure instatusDetailsand in the container'slifecycleDetails; onceUNHEALTHYit needssuccessThresholdconsecutive successes to beHEALTHYagain, as the SDK describes. UnderfailureAction: KILL(the default, per the SDK) a check that reaches its failure threshold stops the container, withgracefulShutdownTimeoutInSeconds, and the restart policy decides what happens next, as the SDK says;NONEonly reports. After a restart the streaks start again and the last status stays until a run changes it. The SDK gives no defaults for the timings; floci-oci uses Kubernetes' (inferred): no initial delay, every 10 seconds, a 1 second timeout, 1 success, 3 failures. Starting or restarting the instance resets every check toUNKNOWN. - Logs.
RetrieveLogsreturns the container's stdout and stderr as text (at most 20 MB).isPreviousis accepted and ignored. - Restarts of floci-oci. A create that was running is marked
FAILED; anACTIVEinstance is started again; a delete that was running finishes. - State reset.
POST /_floci/state/resetremoves the pods and volumes of every tenancy and region, File Storage export volumes included. A create or start still running when the reset arrives removes what it started once it finishes.
With FLOCI_OCI_SERVICES_CONTAINERINSTANCES_MOCK=true nothing touches Docker: instances and
containers are ACTIVE as soon as they are created, work requests are SUCCEEDED, the VNIC gets
the next free address of its subnet, RetrieveLogs is empty, health checks stay UNKNOWN, and
the security context and DNS settings are stored and returned only.
Wire notes
- Create answers
200with theContainerInstance, itsetagandopc-work-request-id; every other write answers202with onlyopc-work-request-id. The SDKs record no status codes; these follow the other work-request-driven services. - Lists are
{"items": [...]}collections withopc-next-page.ListContainerInstancesandListContainerssort bytimeCreated(newest first) ordisplayName. - The work request resource has
entityType: containerInstance, populated from the start: the Terraform provider reads theCREATEDresource from it.WorkRequesthas noerrorsfield; errors are onListWorkRequestErrors. ContainerInstanceSummarycarries nocontainers,vnicsorvolumes, andContainerSummaryno command, arguments or health checks, as in the SDK models.- Deleted instances stay readable with
lifecycleState: DELETED.
Validation
availabilityDomainmust be one of the tenancy's (ListAvailabilityDomains),faultDomainone ofFAULT-DOMAIN-1to3.shapemust be offered in the region andshapeConfigwithin its range (below).- There is exactly one VNIC, and its
subnetIdandnsgIdsmust exist in Networking (400 RelatedResourceNotAuthorizedOrNotFound). The NSGs must be in the subnet's VCN, and a requestedprivateIpcannot be one of the subnet's reserved addresses (400 InvalidParameter, see Networking). - A volume mount must name one of the instance's volumes.
- An
OCI_FSS_FILE_SYSTEMvolume needsmountTargetandexport, each with typeOCIDand anid(400 MissingParameterorInvalidParameter);security.authcan only beSYS. - A start of an instance that is not
INACTIVE, a stop or restart of one that is notACTIVE, and a delete of one alreadyDELETINGorDELETEDare409 IncorrectState.
Shapes
From Oracle's Container Instances Shapes page:
| Shape | OCPUs | Memory | Bandwidth |
|---|---|---|---|
CI.Standard.E4.Flex |
1 to 64 | 1 GB (or one per OCPU) to 64 GB per OCPU, at most 1024 GB | 1 Gbps per OCPU, at most 40 |
CI.Standard.E5.Flex |
1 to 94 | 1 GB to 64 GB per OCPU, at most 1504 GB | 1 Gbps per OCPU, at most 100 |
CI.Standard.A1.Flex |
1 to 76 | 1 GB (or one per OCPU) to 64 GB per OCPU, at most 488 GB | 1 Gbps per OCPU, at most 40 |
CI.Standard.E5.Flex is listed only in the regions that page names. The processor descriptions,
and the memory an instance gets when shapeConfig.memoryInGBs is left out (16 GB per OCPU, 6 for
A1), are not on that page: they follow the Compute shapes of the same series and are inferred.
Not emulated
fsGroupdoes not change the ownership ofEMPTYDIRandCONFIGFILEvolumes, as the SDK says it has no effect on ephemeral volumes.subPathon a volume mount is stored and ignored.
Quickstart
The subnet has to exist first: create one as in the Networking quickstart.
E="--endpoint http://localhost:4599"
TENANCY=ocid1.tenancy.oc1..flocilocaltenancy0000000000000000000000000000000000000000
AD=$(oci iam availability-domain list $E -c "$TENANCY" --query 'data[0].name' --raw-output)
oci container-instances container-instance create $E --compartment-id "$TENANCY" \
--availability-domain "$AD" --shape CI.Standard.E4.Flex \
--shape-config '{"ocpus": 1, "memoryInGBs": 4}' \
--containers '[{"imageUrl": "nginx:1.27"}]' \
--vnics '[{"subnetId": "<subnetId>"}]' \
--wait-for-state SUCCEEDED
oci container-instances container retrieve-logs $E --container-id <containerId> --file -