Tuesday, 2 January 2018

Docker compose 'tricks'

Access a compose container in interactive mode

see: solution on docker forum

Having started docker-compose using a compose file similar to:

version: "2"
services:
  selenium:
      restart: always
      image: stesho/selenium-remote
      ports:
        - "4444:4444"
  centaurtestservers:
      restart: "no"
      image: stesho/centaur-testservers
      ports:
        - "4004:4004"
        - "4005:4005"
        - "4006:4006"
        - "4007:4007"
        - "4008:4008"
      volumes:
        - B:\docker-mount\centaur-build:/tmp/centaur-build
      command: bash -c "echo 'hello world'"
  centaurtests:
      depends_on:
        - "selenium"
        - "centaurtestservers"
      restart: "no"
      image: stesho/centaur-tests

I can run docker ps to list the container now running:


P:\>docker ps

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS                          PORTS                                             NAMES
5b32cca41c49        stesho/selenium-remote       "echo 'hello world'"     2 minutes ago       Restarting (0) 38 seconds ago                                                     centaurtests_selenium_run_1
c046fd91bc9f        stesho/centaur-testservers   "/bin/sh -c '/bin/..."   4 weeks ago         Up 4 weeks                      3004-3008/tcp, 0.0.0.0:4004-4008->4004-4008/tcp   centaurtests_centaurtestservers_1
71fccaf3fabf        stesho/selenium-remote       "sh /opt/selenium/..."   4 weeks ago         Up 4 weeks                      0.0.0.0:4444->4444/tcp                            centaurtests_selenium_1
3b61025ad614        0700d505656c                 "/bin/sh -c 'sourc..."   4 weeks ago         Up 4 weeks                                                                        silly_shirley
5244fdf06b74        stesho/centaur               "/bin/sh -c 'sourc..."   4 weeks ago         Up 4 weeks                      0.0.0.0:3004-3008->3004-3008/tcp                  objective_bassi
92f4b101ad6a        stesho/eprints3              "/bin/bash"              7 weeks ago         Up 7 weeks                      0.0.0.0:8098->8098/tcp                            eprints_pubs

After which I can login to my chosen container in an interactive shell for example:

P:\>docker exec -it objective_bassi bash


Monday, 22 May 2017

Remove Docker overlays and images

To remove all the images and their overlays:

sudo docker rmi `docker images -aq`


If there are any remaining overlays in /var/lib/docker/overlay can we just delete these?

Try to prune docker:

 sudo docker system prune -a -f


Allowing docker write access to volumes mounted on NFS

My development machine (mydev) mounts several directories which are on an NFS mounted filesystem

When I run docker I wish to be able to access and write to the NFS filesystem.

The following is a brief technique:

Inside the dockerfile:


RUN useradd -m -d /home/mydocker mydocker; echo 'usermod -u $HOST_UID mydocker' >> ~/.bash_profile

# what order does this run in?
ENTRYPOINT source /root/.bash_profile && su - mydocker && /bin/bash


If I we to run docker with:

[me@mydev]$ sudo docker -i run -e"HOST_UID=`id -u`" -v /some/nfs/drive:/var/local/drive -t /bin/bash

Then mydocker will have the same uid as the user I ran the sudo with and should be able to access the NFS drive in the same was as the native user (me).

Monday, 6 February 2017

Git: decide that the changes I have made require a new branch

Okay, so I have cloned my repo and started working on a bug fix / feature.  When I come to wanting to commit the feature figure that I need to create  a feature branch.

So I can create and switch branch by:

git checkout [feature branch name]

git status # this will show the branch that my local sandbox is not pointing to)

git commit -m"my message" [my files]

git push origin [feature branch name]

Friday, 3 February 2017

Transfer svn repos to git


(based on the experience of following:  https://www.atlassian.com/git/tutorials/migrating-convert )

required: yum install wget git java git-svn

In the svn repos get the URL of the repository:

: svn info

Get the ids of all users who have committed work to the repository:

svn log --quiet | grep "^r" | awk '{print $3}' | sort | uniq




on the 'transfer machine' setup ssh access /access to your svn repos. For example if using ssh auth create a local user

adduser

then create ssh keys for that user:

ssh-keygen -t rsa

and copy the id_rsa.pub file onto the svn server and cat  >> authorised_keys file

su -

cd ~/home/

download the transfer script:

wget https://bitbucket.org/atlassian/svn-migration-scripts/downloads/svn-migration-scripts.jar




The migrations:

Test the you have the libs and if not install / upgrade

java -jar ~/svn-migration-scripts.jar verify

if all okay

generate an authors file. I hand crafted mine:
authors.txt

jb1 = Joe Bloggs < email@somewhere.com >

Then clone the repo (we used the standard trunk / branches/ tags layout):

git svn clone --stdlayout --authors-file=authors.txt svn+ssh://svn-server.somewhere.on.int.net/usr/src/local/svn-repos/web-world/ [your git repo name]

then see what there is totidy up:

cd [your git repo name ]

java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar clean-git

java -Dfile.encoding=utf-8 -jar ~/svn-migration-scripts.jar clean-git --force

when happy create the repo on bitbucket (if not already)

prepare to send:

git remote add origin https://[git user]@bitbucket.org/[gitowner]/[your git repo name].git

git push -u origin --all

bish bash!

Notes:

For some reason your svn repo does not have tags or branches dirctories. The script will complain eg:

in [your git repo name]/.git/config

add to the section
[svn-remote "svn"]
    branches =
    tags =  



Wednesday, 1 February 2017

sails mocha: Running specific tests in mocha

To avoid running the entire test suite (when writing the tests), you can choose to only run specific tests based on a matching regular expresssion eg:

given snippet of packages file:

"scripts":{
    ...,
    "test": "PORT=9998 NODE_ENV=test mocha -R spec -b --recursive"
}

then

npm test --  --grep ManageSessions

will run any of the tests with a describe title matching *ManageSessions*


Monday, 16 January 2017

Windows docker running out of disk space

By default when installing Docker for windows the docker images file will be installed in the path configured in the Hyper-V manager, which for me happened to be in C:\Users\Public\Public Documents\Hyper-V.

To move the image file you need to:

  1. Stop Docker.
  2. Move the images file (MobyLinuxVM.xhdx) to the location you wish for Hyper-V to store the image
  3. Open Hyper-v and in the setting change the default location to save this image
  4. Uninstall and then re-install docker



voila!