From the project
Announcing TurnKey Docker optimized builds
Please note: This blog post is quite dated, for the latest updated info regarding usage of TurnKey Docker builds, please see the doc page.
As we've mentioned before, making TurnKey easy to deploy no matter your platform of choice is an important goal for the project. TurnKey already supports a mirade of build types including ISO, VMDK, OVF, Amazon EC2, OpenStack, OpenVZ, OpenNode, Xen, and recently added support for LXC.
I'm pleased to announce that today we are updating the above list, with support for Docker.
Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more.
Deploying TurnKey on Docker
All TurnKey appliances are available on the public docker index (generously provided by Docker, Inc), which streamlines deployment. For example:
docker pull turnkeylinux/core-13.0 docker run -i -t -d turnkeylinux/core-13.0
Docker containers can be run in the foreground or the background, so we've tried our best to support all use cases with regards to initialization (aka. inithooks) - secret regeneration, setting of passwords, application configuration, etc.
Depending on your use case, we recommend two options:
Option 1: Initialization via ssh (interactive)
On first login, you will be prompted to initialize the appliance.
CID=$(docker run -i -t -d turnkeylinux/core-13.0)
CIP=$(docker inspect -format='{{.NetworkSettings.IPAddress}}' $CID)
docker logs $CID | grep "Random initial root password"
ssh root@$CIPOption 2: Create new image with preseeded values (non-interactive)
The appliance will initialize itself with the provided configuration. Once initialized, the configuration will be deleted. For more information see inithooks.
mkdir /root/wordpress cat > /root/wordpress/inithooks.conf <<EOF export ROOT_PASS=secretrootpass export DB_PASS=secretmysqlpass export APP_PASS=secretadminwppass export APP_EMAIL=admin@example.com export APP_DOMAIN=www.example.com export HUB_APIKEY=SKIP export SEC_UPDATES=FORCE EOF cat > /root/wordpress/Dockerfile <<EOF FROM turnkeylinux/wordpress-13.0 ADD inithooks.conf /etc/inithooks.conf EOF docker build -t wordpress-13.0 /root/wordpress docker run -i -t -d wordpress-13.0
Notes
Pre-configured run command
Docker is designed for "application or process" containers - for example, running mysql, and only mysql. Docker short-circuits /sbin/init so you can't really "boot" a container like in vanilla LXC.
To work around this, we've included /usr/sbin/start.sh (default run command) which will start all services and drop to a shell. When the shell is exited, the services will be stopped. For this reason, SSH is recommended for regular console usage.
STDIN and TTY options required
The -i and -t options are required to attach STDIN and allocate a TTY to the container. Unfortunately this cannot be pre-configured as it is not yet supported.
Pre-configured to expose ports
All TurnKey Docker appliances are configured to expose their custom services. This means that the host can access the services, but they are not exposed to the network.
Exposing ports to the network needs to be done at runtime (docs), for example:
# bind port 80 on the host to the container's port 80 docker run -i -t -d -p 80:80 turnkeylinux/lamp-13.0
Skipping security updates on first boot
During development I added support to start.sh to override the default SEC_UPDATES value to speed up my testing. I was going to remove this support or leave it undocumented, but decided others might find it useful when testing (and only in testing).
# THIS IS NOT RECOMMENDED, USE AT YOUR OWN RISK! docker run -i -t -d -e SEC_UPDATES=SKIP turnkeylinux/openldap-13.0
Keep in mind, this is the initial release of TurnKey Docker support, so let us know what you think. If you have ideas for improvement, or if you come across any issues (ie. we haven't tested all appliances as of yet), drop us a line.
I'll try this out next week!