### Bash: Start Container Source: https://context7.com/oracle/railcar/llms.txt Starts a previously created container, initiating prestart and poststart hooks. The process involves loading configuration, connecting to sockets, executing hooks, and signaling execution. The running state can be verified with the 'state' command. ```bash # Start created container railcar start my-container # The start process: # 1. Loads config from instance directory # 2. Connects to trigger socket if available # 3. Executes prestart hooks # 4. Signals container to begin execution # 5. Writes process PID # 6. Executes poststart hooks # Verify running state railcar state my-container # Output: # { # "version": "0.2.0", # "id": "my-container", # "status": "running", # "pid": 12345, # "bundle": "/path/to/bundle", # "annotations": {} # } ``` -------------------------------- ### Integrate Railcar as Docker Runtime Source: https://context7.com/oracle/railcar/llms.txt Steps to configure and use Railcar as a custom Docker runtime backend. This involves starting the Docker daemon with the experimental flag and specifying the Railcar runtime path, or configuring it in `daemon.json`. Examples show how to run containers using the custom runtime and verify its usage. ```bash # Start Docker daemon with Railcar runtime dockerd --experimental --add-runtime "rc=/usr/local/bin/railcar" # Or configure in /etc/docker/daemon.json { "runtimes": { "rc": { "path": "/usr/local/bin/railcar" } } } # Restart Docker systemctl restart docker # Run container with Railcar docker run -it --rm --runtime=rc ubuntu:20.04 /bin/bash # Daemonized container docker run -dt --rm --runtime=rc --name my-app nginx:latest # Check container is using Railcar docker inspect my-app | jq '.[0].HostConfig.Runtime' # Output: "rc" # View Railcar process ps aux | grep railcar ``` -------------------------------- ### Root Filesystem Setup Source: https://context7.com/oracle/railcar/llms.txt Configures the container's root filesystem and mount points. It specifies the path to the rootfs, whether it's read-only, and defines various mounts like /proc, /dev, /sys, and temporary directories. It also includes bind mounts for persistent storage, crucial for initializing a functional container environment. ```json { "root": { "path": "rootfs", "readonly": true }, "mounts": [ { "destination": "/proc", "type": "proc", "source": "proc", "options": ["nosuid", "noexec", "nodev"] }, { "destination": "/dev", "type": "tmpfs", "source": "tmpfs", "options": ["nosuid", "strictatime", "mode=755", "size=65536k"] }, { "destination": "/dev/pts", "type": "devpts", "source": "devpts", "options": ["nosuid", "noexec", "newinstance", "ptmxmode=0666", "mode=0620"] }, { "destination": "/sys", "type": "sysfs", "source": "sysfs", "options": ["nosuid", "noexec", "nodev", "ro"] }, { "destination": "/tmp", "type": "tmpfs", "source": "tmpfs", "options": ["nosuid", "nodev"] }, { "destination": "/data", "type": "bind", "source": "/host/data", "options": ["rbind", "rw"] } ] } // Mount process: // 1. Set rootfs propagation (shared/private/slave) // 2. Bind mount rootfs to itself // 3. Mount all filesystem entries // 4. Create default device nodes // 5. Pivot root into container rootfs // 6. Mask sensitive paths // 7. Make specified paths readonly // 8. Remount rootfs readonly if specified ``` -------------------------------- ### Container Lifecycle Management Source: https://context7.com/oracle/railcar/llms.txt Commands for creating, running, starting, and managing the lifecycle of containers. ```APIDOC ## POST /run ### Description Executes a complete container from an OCI configuration bundle in a single operation. ### Method POST ### Endpoint `/run` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to run. #### Query Parameters - **bundle** (string) - Optional - Path to the OCI bundle directory. Defaults to the current directory. - **daemon** (boolean) - Optional - Whether to run the container in daemonized mode. - **no-init** (boolean) - Optional - Whether to run the container without an init process. ### Request Example ```json { "ociVersion": "1.0.0", "process": { "terminal": true, "user": {"uid": 0, "gid": 0}, "args": ["/bin/sh"], "env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"], "cwd": "/" }, "root": { "path": "rootfs", "readonly": false }, "hostname": "mycontainer", "mounts": [ { "destination": "/proc", "type": "proc", "source": "proc" } ], "linux": { "namespaces": [ {"type": "pid"}, {"type": "network"}, {"type": "ipc"}, {"type": "uts"}, {"type": "mount"} ] } } ``` ### Response #### Success Response (200) - **container_id** (string) - The ID of the created and running container. #### Response Example ```json { "container_id": "my-container" } ``` ## POST /create ### Description Creates a container without starting it, enabling a two-phase container lifecycle management. ### Method POST ### Endpoint `/create` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to create. #### Query Parameters - **console-socket** (string) - Optional - Path to a console socket for interactive TTY. - **console** (string) - Optional - Path to an external console device. - **no-trigger** (boolean) - Optional - Use double fork mode without triggering the container. - **pid-file** (string) - Optional - Path to write the container's PID file. ### Request Example ```bash curl -X POST http://localhost:8080/create?console-socket=/tmp/console.sock my-container ``` ### Response #### Success Response (200) - **status** (string) - The status of the container (e.g., "created"). - **pid** (integer) - The process ID of the container init process. - **bundle** (string) - The path to the container's bundle directory. #### Response Example ```json { "version": "0.2.0", "id": "my-container", "status": "created", "pid": 12345, "bundle": "/path/to/bundle", "annotations": {} } ``` ## POST /start ### Description Starts a previously created container, executing prestart and poststart hooks. ### Method POST ### Endpoint `/start` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to start. ### Request Example ```bash curl -X POST http://localhost:8080/start my-container ``` ### Response #### Success Response (200) - **status** (string) - The updated status of the container (e.g., "running"). #### Response Example ```json { "version": "0.2.0", "id": "my-container", "status": "running", "pid": 12345, "bundle": "/path/to/bundle", "annotations": {} } ``` ``` -------------------------------- ### Bash: Create Container Source: https://context7.com/oracle/railcar/llms.txt Creates a container without starting it, allowing for staged lifecycle management. Supports options for console sockets, external consoles, no-trigger mode, and PID file output. The state can be queried using the 'state' command. ```bash # Create container with console socket railcar create --console-socket /tmp/console.sock my-container # Create with external console railcar create --console /dev/pts/0 my-container # Create with no-trigger (double fork mode) railcar create --no-trigger my-container # Create with pid file output railcar create --pid-file /var/run/container.pid my-container # Container state after creation railcar state my-container # Output: # { # "version": "0.2.0", # "id": "my-container", # "status": "created", # "pid": 12345, # "bundle": "/path/to/bundle", # "annotations": {} # } ``` -------------------------------- ### Configure Container Lifecycle Hooks in Rust Source: https://context7.com/oracle/railcar/llms.txt Defines a JSON structure for configuring custom scripts to execute at various container lifecycle events (prestart, poststart, poststop). Each hook can specify the script path, arguments, environment variables, and a timeout. An example bash script demonstrates how a hook can receive and process container state information via JSON on stdin. ```json { "hooks": { "prestart": [ { "path": "/usr/local/bin/setup-network.sh", "args": ["/usr/local/bin/setup-network.sh", "arg1", "arg2"], "env": ["FOO=bar", "BAZ=qux"], "timeout": 30 } ], "poststart": [ { "path": "/usr/local/bin/notify-started.sh", "args": ["/usr/local/bin/notify-started.sh"], "timeout": 10 } ], "poststop": [ { "path": "/usr/local/bin/cleanup.sh", "args": ["/usr/local/bin/cleanup.sh"], "timeout": 60 } ] } } ``` ```bash # Example hook receiving state: #!/bin/bash STATE=$(cat) CONTAINER_ID=$(echo $STATE | jq -r '.id') CONTAINER_PID=$(echo $STATE | jq -r '.pid') echo "Container $CONTAINER_ID started with PID $CONTAINER_PID" ``` -------------------------------- ### Docker and OCI Compatibility Notes for Railcar Source: https://context7.com/oracle/railcar/llms.txt Details the compatibility of Railcar with various Docker operations and OCI standards. Lists supported and unsupported Docker commands, and explains how to configure the state directory and logging compatibility for Railcar. ```bash # Supported Docker operations: docker run --runtime=rc ... # Full support docker create --runtime=rc ... # Full support docker start ... # Full support docker stop ... # Full support (sends SIGTERM) docker kill ... # Full support (custom signals) docker rm ... # Full support docker ps ... # Full support # Unsupported operations: docker exec ... # Not implemented docker pause ... # Not implemented docker unpause ... # Not implemented docker checkpoint ... # Not implemented # State directory # Default: /run/railcar// # Override with: --root /custom/path # Logging compatibility railcar --log /var/log/railcar.log ... # Creates empty file for Docker compatibility # Actual logs go to stderr, captured by Docker ``` -------------------------------- ### Configure Block I/O Throttling for Containers Source: https://context7.com/oracle/railcar/llms.txt Manages disk I/O bandwidth and IOPS for container storage. This includes setting weights, device-specific weights, read/write bandwidth limits (Bps), and read/write IOPS limits for specified block devices. ```json // config.json blkio configuration { "linux": { "resources": { "blockIO": { "weight": 500, // I/O weight (10-1000) "leafWeight": 500, "weightDevice": [ { "major": 8, "minor": 0, "weight": 500, "leafWeight": 300 } ], "throttleReadBpsDevice": [ { "major": 8, "minor": 0, "rate": 10485760 // 10MB/s read limit } ], "throttleWriteBpsDevice": [ { "major": 8, "minor": 0, "rate": 5242880 // 5MB/s write limit } ], "throttleReadIOPSDevice": [ { "major": 8, "minor": 0, "rate": 1000 // 1000 IOPS read limit } ], "throttleWriteIOPSDevice": [ { "major": 8, "minor": 0, "rate": 500 // 500 IOPS write limit } ] } } } } ``` -------------------------------- ### Configure CPU Resources for Containers Source: https://context7.com/oracle/railcar/llms.txt Defines CPU scheduling and quota limits for container processes, including shares, quota, period, and CPU/memory affinity. These settings map to specific files within the cgroups filesystem for runtime control. ```json // config.json CPU resources example { "linux": { "resources": { "cpu": { "shares": 1024, // CPU shares (relative weight) "quota": 100000, // CPU quota in microseconds "period": 100000, // CPU period in microseconds "realtimePeriod": 1000000, "realtimeRuntime": 950000, "cpus": "0-3", // CPUs to use "mems": "0-1" // Memory nodes to use } } } } // Implementation in cgroups.rs: // Writes to cgroup files: // - cpu.shares -> cpu.shares // - cpu.quota -> cpu.cfs_quota_us // - cpu.period -> cpu.cfs_period_us // - cpu.realtimePeriod -> cpu.rt_period_us // - cpu.realtimeRuntime -> cpu.rt_runtime_us // - cpuset.cpus from cpus field // - cpuset.mems from mems field ``` -------------------------------- ### Manage Linux Capabilities for Containers Source: https://context7.com/oracle/railcar/llms.txt Configures Linux capabilities for containers, allowing fine-grained control over process privileges. This involves defining bounding, effective, inheritable, permitted, and ambient capability sets to minimize container attack surface. ```json // config.json capabilities configuration { "process": { "capabilities": { "bounding": [ "CAP_AUDIT_WRITE", "CAP_KILL", "CAP_NET_BIND_SERVICE" ], "effective": [ "CAP_AUDIT_WRITE", "CAP_KILL", "CAP_NET_BIND_SERVICE" ], "inheritable": [ "CAP_AUDIT_WRITE", "CAP_KILL", "CAP_NET_BIND_SERVICE" ], "permitted": [ "CAP_AUDIT_WRITE", "CAP_KILL", "CAP_NET_BIND_SERVICE" ], "ambient": [ "CAP_NET_BIND_SERVICE" ] } } } // Implementation details: // 1. Drops all capabilities not in bounding set // 2. Sets effective, permitted, inheritable sets // 3. Attempts to set ambient capabilities (may fail on older kernels) // 4. All operations done after uid/gid changes ``` -------------------------------- ### Bash: List Container Processes Source: https://context7.com/oracle/railcar/llms.txt Queries and lists running processes within a container. Outputs a JSON array of PIDs. This functionality can be used with external tools like 'jq' to process and display detailed process information. ```bash # List container processes railcar ps my-container # Output format (JSON array of PIDs) [12345] # Multiple processes (if exec supported) [12345, 12346, 12347] # Use with external tools PIDS=$(railcar ps my-container) for pid in $(echo $PIDS | jq -r '.[]'); do ps -p $pid -o pid,ppid,cmd done ``` -------------------------------- ### Rust: Run Container Source: https://context7.com/oracle/railcar/llms.txt Executes a container from an OCI configuration bundle. Supports custom bundle directories, daemonized execution, and disabling the init process. Requires a valid config.json within the bundle. ```rust // Command-line usage railcar run my-container // With custom bundle directory railcar -b /path/to/bundle run my-container // Daemonized container railcar -d run my-container // Without init process railcar run --no-init my-container // Example config.json structure required in bundle { "ociVersion": "1.0.0", "process": { "terminal": true, "user": {"uid": 0, "gid": 0}, "args": ["/bin/sh"], "env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"], "cwd": "/" }, "root": { "path": "rootfs", "readonly": false }, "hostname": "mycontainer", "mounts": [ { "destination": "/proc", "type": "proc", "source": "proc" } ], "linux": { "namespaces": [ {"type": "pid"}, {"type": "network"}, {"type": "ipc"}, {"type": "uts"}, {"type": "mount"} ] } } ``` -------------------------------- ### Configure Security Path Masking in Rust Source: https://context7.com/oracle/railcar/llms.txt Defines security configurations for masking sensitive paths and enforcing read-only restrictions on Linux systems using a JSON format. Masked paths are bind-mounted over /dev/null, and read-only paths are remounted. Non-existent paths are ignored, and path validation prevents directory traversal. ```json { "linux": { "maskedPaths": [ "/proc/kcore", "/proc/latency_stats", "/proc/timer_list", "/proc/timer_stats", "/proc/sched_debug", "/proc/scsi", "/sys/firmware" ], "readonlyPaths": [ "/proc/asound", "/proc/bus", "/proc/fs", "/proc/irq", "/proc/sys", "/proc/sysrq-trigger" ] } } ``` -------------------------------- ### Device Node Management Source: https://context7.com/oracle/railcar/llms.txt Manages the creation and configuration of device nodes within the container's filesystem. It allows specifying custom devices with their types (character or block), major/minor numbers, file modes, and ownership. This is essential for providing necessary device access to applications running inside the container. ```json { "linux": { "devices": [ { "path": "/dev/fuse", "type": "c", "major": 10, "minor": 229, "fileMode": 438, "uid": 0, "gid": 0 }, { "path": "/dev/sda", "type": "b", "major": 8, "minor": 0, "fileMode": 432, "uid": 0, "gid": 6 } ] } } // Default devices created automatically: // - /dev/null (c 1:3) // - /dev/zero (c 1:5) // - /dev/full (c 1:7) // - /dev/tty (c 5:0) // - /dev/urandom (c 1:9) // - /dev/random (c 1:8) // Default symlinks: // - /dev/fd -> /proc/self/fd // - /dev/stdin -> /proc/self/fd/0 // - /dev/stdout -> /proc/self/fd/1 // - /dev/stderr -> /proc/self/fd/2 // - /dev/ptmx -> /dev/pts/ptmx ``` -------------------------------- ### Namespace Isolation Configuration Source: https://context7.com/oracle/railcar/llms.txt Defines Linux namespace configurations for process, network, and filesystem isolation. It specifies different namespace types (pid, network, ipc, uts, mount, user, cgroup) and provides UID/GID mappings for user namespace management. This is essential for creating isolated container environments. ```json { "linux": { "namespaces": [ { "type": "pid" }, { "type": "network" }, { "type": "ipc" }, { "type": "uts" }, { "type": "mount" }, { "type": "user", "path": "" }, { "type": "cgroup" } ], "uidMappings": [ { "containerID": 0, "hostID": 1000, "size": 1000 } ], "gidMappings": [ { "containerID": 0, "hostID": 1000, "size": 1000 } ] } } // Namespace creation order: // 1. Clone with CLONE_NEWUSER first if specified // 2. Write uid_map and gid_map // 3. Unshare remaining namespaces // 4. Enter existing namespaces via setns if path specified ``` -------------------------------- ### Set Memory Resource Limits for Containers Source: https://context7.com/oracle/railcar/llms.txt Establishes memory limits, soft limits (reservations), swap usage, kernel memory, and kernel TCP buffer sizes for containers. It also configures the OOM killer behavior. These parameters correspond to specific cgroup memory control files. ```json // config.json memory resources { "linux": { "resources": { "memory": { "limit": 536870912, // 512MB memory limit "reservation": 268435456, // 256MB soft limit "swap": 1073741824, // 1GB swap limit "kernel": 134217728, // 128MB kernel memory "kernelTCP": 67108864, // 64MB kernel TCP buffer "swappiness": 60 // Swappiness (0-100) }, "disableOOMKiller": false } } } // Cgroup file mappings: // memory.limit_in_bytes <- limit // memory.soft_limit_in_bytes <- reservation // memory.memsw.limit_in_bytes <- swap // memory.kmem.limit_in_bytes <- kernel // memory.kmem.tcp.limit_in_bytes <- kernelTCP // memory.swappiness <- swappiness // memory.oom_control <- disableOOMKiller ``` -------------------------------- ### Seccomp System Call Filtering Configuration Source: https://context7.com/oracle/railcar/llms.txt Configures seccomp (secure computing mode) to filter system calls, reducing the attack surface and enforcing security policies. It specifies default actions, supported architectures, and rules for allowing or denying specific system calls and their arguments. This configuration is crucial for enhancing container security. ```json { "linux": { "seccomp": { "defaultAction": "SCMP_ACT_ERRNO", "architectures": [ "SCMP_ARCH_X86_64", "SCMP_ARCH_X86", "SCMP_ARCH_X32" ], "syscalls": [ { "names": ["read", "write", "open", "close"], "action": "SCMP_ACT_ALLOW" }, { "names": ["chmod"], "action": "SCMP_ACT_ALLOW", "args": [ { "index": 1, "value": 511, "op": "SCMP_CMP_NE" } ] }, { "names": ["socket"], "action": "SCMP_ACT_ERRNO", "args": [ { "index": 0, "value": 2, "valueTwo": 0, "op": "SCMP_CMP_EQ" } ] } ] } } } // Actions: // SCMP_ACT_KILL - kill process // SCMP_ACT_TRAP - send SIGSYS // SCMP_ACT_ERRNO - return errno // SCMP_ACT_TRACE - trace syscall // SCMP_ACT_ALLOW - allow syscall ``` -------------------------------- ### Bash: Kill Container Source: https://context7.com/oracle/railcar/llms.txt Sends signals to running containers to terminate them gracefully or forcefully. Supports default SIGTERM and specific signals by name or number. Common signals like TERM, KILL, and HUP are detailed. ```bash # Send SIGTERM (default) railcar kill my-container # Send specific signal railcar kill my-container SIGKILL railcar kill my-container SIGHUP railcar kill my-container 9 # Common signals: # TERM (15) - graceful shutdown # KILL (9) - immediate termination # HUP (1) - reload configuration # INT (2) - interrupt # USR1 (10) - user-defined signal 1 # USR2 (12) - user-defined signal 2 ``` -------------------------------- ### Container Management Operations Source: https://context7.com/oracle/railcar/llms.txt Commands for killing, deleting, and querying the status of containers. ```APIDOC ## POST /kill ### Description Sends signals to running containers for graceful or forceful termination. ### Method POST ### Endpoint `/kill` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to send a signal to. #### Query Parameters - **signal** (string) - Optional - The signal to send. Defaults to SIGTERM. Accepts signal names (e.g., SIGKILL) or numbers (e.g., 9). ### Request Example ```bash curl -X POST http://localhost:8080/kill my-container?signal=SIGKILL ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the signal was sent. #### Response Example ```json { "message": "Signal SIGKILL sent to container my-container" } ``` ## DELETE /delete ### Description Removes a container and cleans up all associated resources including cgroups and state files. ### Method DELETE ### Endpoint `/delete` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to delete. #### Query Parameters - **force** (boolean) - Optional - Force delete a running container. This will kill the container before deleting. ### Request Example ```bash curl -X DELETE http://localhost:8080/delete my-container?force=true ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the container was deleted. #### Response Example ```json { "message": "Container my-container deleted successfully" } ``` ## GET /state ### Description Queries the current state and process information of a container. ### Method GET ### Endpoint `/state` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to query the state of. ### Request Example ```bash curl http://localhost:8080/state my-container ``` ### Response #### Success Response (200) - **version** (string) - The state version. - **id** (string) - The container ID. - **status** (string) - The current status of the container (e.g., "created", "running", "stopped"). - **pid** (integer) - The process ID of the container init process. - **bundle** (string) - The path to the container's bundle directory. - **annotations** (object) - Key-value pairs for container annotations. #### Response Example ```json { "version": "0.2.0", "id": "my-container", "status": "running", "pid": 12345, "bundle": "/path/to/bundle", "annotations": {} } ``` ## GET /ps ### Description Queries the running processes within a container. ### Method GET ### Endpoint `/ps` ### Parameters #### Path Parameters - **container_name** (string) - Required - The name of the container to list processes from. ### Request Example ```bash curl http://localhost:8080/ps my-container ``` ### Response #### Success Response (200) - **pids** (array) - A JSON array of process IDs (PIDs) running within the container. #### Response Example ```json [ 12345, 12346, 12347 ] ``` ``` -------------------------------- ### Bash: Delete Container Source: https://context7.com/oracle/railcar/llms.txt Removes a container and cleans up associated resources like cgroups and state files. Supports force deletion of running containers. The deletion process includes checking process status, signaling, killing init, removing cgroups, executing hooks, and cleaning state directories. ```bash # Delete stopped container railcar delete my-container # Force delete running container railcar delete --force my-container # Delete process: # 1. Checks if process is still running # 2. Sends SIGKILL if --force specified # 3. Kills init process # 4. Removes cgroup directories # 5. Executes poststop hooks # 6. Removes state directory # Error handling railcar delete non-existent-container # Returns success for Docker compatibility ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.