Think Dockerfile & docker-compose for rkt containers
rkd
(aka rock-it dev) is a simple tool to build
and run rkt containers locally.
$ rkd
Development environments powered by rkt containers, with ease.
Usage:
rkd [command]
Available Commands:
build Build the containers
help Help about any command
up Run the container
version Print the version number of rkd
Flags:
-h, --help help for rkd
Use "rkd [command] --help" for more information about a command.
$ sudo rkd up
/root/.rkd/5290facf0b502d01ba15b7de9a1b9633.aci already built
/root/.rkd/a023872855269062eca818f2ea8c0b32.aci already built
rkt --insecure-options=image --net=host run --interactive --volume src,kind=host,source=/home/odino/projects/go/src/github.com/odino/rkd/example/src /root/.rkd/a023872855269062eca818f2ea8c0b32.aci
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
server started...
Suppose you have a NodeJS webserver running locally with docker-compose and want to convert it to rkt, without using conversion tool like docker2aci & the likes.
First, create your prod.rkd
which is basically docker's Dockerfile
:
set-name example.com/node-hello
dep add quay.io/coreos/alpine-sh
run -- apk add --update nodejs
copy src /src
set-working-directory /src
set-exec -- node index.js
port add www tcp 8080
and create a dev.rkd
which is your new docker-compose.yml
, where you can
define commands dependencies you only need on your local machine:
run -- npm install -g nodemon
mount add src src
set-exec -- nodemon index.js
That's it, now run rkd up
in the current folder:
sudo rkd up
Building /root/.rkd/prod-5290facf0b502d01ba15b7de9a1b9633.aci
acbuild begin
acbuild set-name example.com/node-hello
acbuild dep add quay.io/coreos/alpine-sh
acbuild run -- apk add --update nodejs
Downloading quay.io/coreos/alpine-sh: [========================] 2.65 MB/2.65 MB
fetch http://dl-4.alpinelinux.org/alpine/v3.2/main/x86_64/APKINDEX.tar.gz
(1/4) Installing libgcc (4.9.2-r6)
(2/4) Installing libstdc++ (4.9.2-r6)
(3/4) Installing libuv (1.5.0-r0)
(4/4) Installing nodejs (0.12.10-r0)
Executing busybox-1.23.2-r0.trigger
OK: 28 MiB in 19 packages
acbuild copy src /src
acbuild set-working-directory /src
acbuild set-exec -- node index.js
acbuild port add www tcp 8080
acbuild write /root/.rkd/prod-5290facf0b502d01ba15b7de9a1b9633.aci
acbuild end
Building /root/.rkd/dev-a023872855269062eca818f2ea8c0b32.aci
acbuild begin ./prod.aci
acbuild run -- npm install -g nodemon
Downloading quay.io/coreos/alpine-sh: [========================] 2.65 MB/2.65 MB
npm WARN optional dep failed, continuing [email protected]
/usr/bin/nodemon -> /usr/lib/node_modules/nodemon/bin/nodemon.js
[email protected] /usr/lib/node_modules/nodemon
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
acbuild mount add src src
acbuild set-exec -- nodemon index.js
acbuild write /root/.rkd/dev-a023872855269062eca818f2ea8c0b32.aci
acbuild end
rkt --insecure-options=image --net=host run --interactive --volume src,kind=host,source=/home/odino/projects/go/src/github.com/odino/rkd/example/src /root/.rkd/dev-a023872855269062eca818f2ea8c0b32.aci
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node index.js`
server started...
and you can head to localhost:8080.
Make sure acbuild is installed in your system.
Builds for a few systems are available in the releases.
Alternatively, you can compile it straight away:
git clone [email protected]:odino/rkd.git
cd rkd
go build -o rkd main.go
mv rkd /usr/local/bin
and then you have the rkd
executable up & running.
One of the arguments against rkt is that building and running containers seems generally more complicated than using docker, so I decided to figure out a way to replicate docker's simplicity on dev environments -- 2 files, one command, running app.
The *.rkd
files are basically a list or acbuild
instructions used for
building 2 ACIs (prod.aci
& dev.aci
): rkd
scans them, building the ACIs,
and bases dev.aci
off of what it build in prod.aci
.
There's a plethora of stuff that could / needs to be done here as this is an early stage weekend project. There's very less error handling etc in the codebase and that's something I wish to work on granted that (1) I can find the time and (2) there's some interest here.