ADAMKDEAN

Copying files from one container to another

Published Sunday, 7 June 2015

This only works on OS X as I'm using pbcopy and pbpaste. You may replace these as you see fit. Also I'm using superdocker here, you can swap that for docker if you like, it makes no difference.

What I needed to do was copy some SSL certificates from one container to another. I wanted the easiest way of doing this for the future. Thus I came up with this somewhat messy solution. I like it though. In this case the source container is called 'registry' and the destination container is a data volume container called 'publisherd-data'.

superdocker exec -ti $(superdocker ps | grep registry | awk '{print $1}') \
    cat /go/src/github.com/docker/distribution/certs/domain.crt | \
    pbcopy && \
    superdocker run --rm -ti \
        --volumes-from publisherd-data \
        ubuntu bash -c "echo '$(pbpaste)' > /etc/nginx/certs/registry.domain.com.crt"

superdocker exec -ti $(superdocker ps | grep registry | awk '{print $1}') \
    cat /go/src/github.com/docker/distribution/certs/domain.key | \
    pbcopy && \
    superdocker run --rm -ti \
        --volumes-from publisherd-data \
        ubuntu bash -c "echo '$(pbpaste)' > /etc/nginx/certs/registry.domain.com.key"

To break it down, we first grab the certificate by running docker exec on the source container, which we find by doing a quick docker ps | grep | awk.

superdocker exec -ti $(superdocker ps | grep registry | awk '{print $1}') \
    cat /go/src/github.com/docker/distribution/certs/domain.crt

Next we pipe that to pbcopy, the OS X clibpoard utility.

superdocker exec -ti $(superdocker ps | grep registry | awk '{print $1}') \
    cat /go/src/github.com/docker/distribution/certs/domain.crt | \
    pbcopy

Then we run an ethereal container which we connect to the destination data volume container. We then simply empty our clipboard into the destination file.

superdocker exec -ti $(superdocker ps | grep registry | awk '{print $1}') \
    cat /go/src/github.com/docker/distribution/certs/domain.crt | \
    pbcopy && \
    superdocker run --rm -ti \
        --volumes-from publisherd-data \
        ubuntu bash -c "echo '$(pbpaste)' > /etc/nginx/certs/registry.domain.com.crt"

It's a figurative mouthful, but it does the trick without saving your certs anywhere. You might also want to clear that clipboard afterwards though.

echo '' | pbcopy

Share directories between two containers

Published Monday, 1 June 2015

Create data volume container:

docker run -d \
    -v /var/test/ \
    --name test-data \
    busybox

Start one container using it:

docker run -d \
    --name test-1 \
    --volumes-from test-data \
    adamkdean/baseimage bash -c "while true; do echo 'ping'; sleep 5; done"

Start another using it:

docker run -d \
    --name test-2 \
    --volumes-from test-data \
    adamkdean/baseimage bash -c "while true; do echo 'ping'; sleep 5; done"

Attach to the first:

docker exec -ti test-1 bash
root@7bfff33a2309:/# cd /var/test/
root@7bfff33a2309:/var/test# ls

Attach to the second:

docker exec -ti test-2 bash
root@7bfff33a2309:/# cd /var/test/
root@69e9a3cc34a2:/var/test# ls

Create a file in the first one:

root@7bfff33a2309:/var/test# touch test-file

Check in the second one:

root@69e9a3cc34a2:/var/test# ls
test-file

Both test-1 and test-2 are sharing the data on the data volume container test-data.

Remove all exited containers

Published Wednesday, 27 May 2015

This removes all exited containers.

docker ps -a | grep 'Exited' | awk '{print $1}' | xargs --no-run-if-empty docker rm

Use with care as it will also removed Data Volume Containers.

Installing Node.js on a Raspberry Pi

Published Friday, 15 May 2015

Raspbian is based on of Debian Wheezy, so things are a little different than the standard Ubuntu 14.04 installs. Remember to always read a script before you curl it to bash.

curl -sLS https://apt.adafruit.com/add | sudo bash
sudo apt-get install node

Now check it's running okay...

pi@raspberrypi ~ $ node -v
v0.12.0

Ok so it's a little behind but still on 0.12.X.

Notes on Raspberry Pi & Arduino

Published Friday, 15 May 2015

Using NOOBS, install Raspbian. It's probably the most supported distro for the Pi. (https://www.raspberrypi.org/help/noobs-setup/)

Setup the Raspberry Pi to connect automatically to WiFi. I've used a TP-Link TL-WN321G without any issues. (http://weworkweplay.com/play/automatically-connect-a-raspberry-pi-to-a-wifi-network/)

I'm using an old pre-2011 Arduino Uno. It's firmware version is actually 0.00, but I was able to get it working with Firmata. Firmata is a library which enables communication between host and arduino. It allows you to use JavaScript frameworks such as http://johnny-five.io/ to control your arduino with Node.

You only need to put Firmata on the arduino once, so I did it on my MacBook. After this, the Arduino just starts up ready to communicate. No more programming required. Tethering is required, as the host will now wear the trousers.

First, download the Arduino IDE. On OS X, brew cask update && brew cask install arduino. Once installed, run it, make sure the arduino is connected via USB. Make sure the correct board and port are seleted in the IDE. Go to File, Examples, Firmata, and then StandardFirmata. Upload this to your board. Now you're set.

Let's quickly test it. Using Node, install johnny-five. Then stick an LED in Arduino pins 13 and GND. Then run the hello world blink code:

var five = require("johnny-five"),
    board = new five.Board();

board.on("ready", function () {
    var led = new five.Led(13);
    led.blink(500);
});

The LED should blink. If it doesn't, it's time to get your Google on.

Moving on, we want to control the Arduino via the Raspberry Pi. For this, you need to manage your power consumption properly.

Step 1. Power on raspberrypi with WiFi dongle connected. Wait for it to connect to network.
Step 2. Start a continuous ping of the raspberrypi to check it's connectivity.
Step 3. Power on your arduino with an external power supply.
Step 4. Plug in the USB into the raspberrypi.
Step 5. Plug in the USB to the arduino.

I don't know for sure, but I think that by powering on the arduino with external power first and then connecting it via USB, it disables the USB power consumption, which stops your raspberrypi from throwing a fit.

Next article will cover: johnny-five arduino code/setup

 
Showing posts 1-5 of 165