-*- outline -* * Docker usage These notes assume that you have some basic working knowledge with administrating a Linux (Ubuntu-based) system. ** Links and docu Detailed on-line documentation on docker is here https://docs.docker.com/userguide/ A useful cheat sheet of main commands and common usage is here https://github.com/wsargent/docker-cheat-sheet ** Setup My notes from using docker to create a container with GHC installed and then running the Haskell exercises: This is running on a Ubuntu 14.10 machine, Docker version 1.5.0, build a8a31ef --(rigel[124](4.3))-- hostname rigel --(rigel[125](4.3))-- uname -a Linux rigel 3.16.0-23-generic #31-Ubuntu SMP Tue Oct 21 17:56:17 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux ** Creating a container First we need to create container. Use sudo docker images to check locally available images; most mainstream distros are supported: -(rigel[126](4.3))-- sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.10 78949b1e1cfd 12 days ago 194.4 MB ... Now we need to create a container, using an existing image of a Linux distro in the docker repo: --(rigel[120](4.3))-- sudo docker create -t -i ubuntu /bin/bash e9c2c3771b9ede0af7819e74093d6f7758e65c6f31924e8bae53ecbcae029966 When you do this the first time, docker will download the relevant image from the docker repository, which will take while. The next time, as shown above, it will pick-up the image locally, and report the ID of the newly created image. ** Starting a container Next, we start this container, using -i ID to attach to the one above. --(rigel[121](4.3))-- sudo docker start -a -i e9c2c3771b9ede0af7819e74093d6f7758e65c6f31924e8bae53ecbcae029966 The prompt root@e9c2c3771b9e:/# shows that you are now inside the container. You are root in a fresh container, without user accounts so far. If you use that container more frequently you should create a user before continuing. In this example, we continue as root (just inside the container). ** Installing GHC inside the container We check whether ghc is installed: root@e9c2c3771b9e:/# which ghc We find nothing, so we need to install it. We use Ubuntu's apt- toolset to search for a GHC package (Glasgow Haskell Compiler) in all repos. root@e9c2c3771b9e:/# apt-cache search ghc Bad luck, it's not in any of the current repos! However, by some magic (or doing a Google search) we know that it is in the 'multiverse' repo. To enable the 'multiverse' repo that is holding GHC, we need to edit the /etc/apt/sources.list file. root@e9c2c3771b9e:/# less /etc/apt/sources.list Naturally, we need an editor to do this, but none is available at this point: root@e9c2c3771b9e:/# which vim root@e9c2c3771b9e:/# which nano Therefore, we install nano as a fairly minimal editor: root@e9c2c3771b9e:/# apt-get install nano ... Now we can edit the file /etc/apt/sources.list like this root@e9c2c3771b9e:/# nano /etc/apt/sources.list Inside nano, go to the end of the file, where you'll find these lines ... deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted deb http://archive.ubuntu.com/ubuntu/ trusty-security universe deb-src http://archive.ubuntu.com/ubuntu/ trusty-security universe # deb http://archive.ubuntu.com/ubuntu/ trusty-security multiverse <============ this is the one we want to enable # deb-src http://archive.ubuntu.com/ubuntu/ trusty-security multiverse You need to uncomment the last but one line, to enable the trusty-security multiverse repo. Now, the file should look like ... deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted deb-src http://archive.ubuntu.com/ubuntu/ trusty-security main restricted deb http://archive.ubuntu.com/ubuntu/ trusty-security universe deb-src http://archive.ubuntu.com/ubuntu/ trusty-security universe deb http://archive.ubuntu.com/ubuntu/ trusty-security multiverse # deb-src http://archive.ubuntu.com/ubuntu/ trusty-security multiverse Exit nano (^X) and save the file. Then update the local info about all repos: root@e9c2c3771b9e:/# apt-get update Now, searching for GHC will find many packages (in the new repo): root@e9c2c3771b9e:/# apt-get search ghc ghc - The Glasgow Haskell Compilation system ghc-doc - Documentation for the Glasgow Haskell Compilation system ... Now, we can install ghc (provdiing both a compiler and an interpreter for Haskell): root@e9c2c3771b9e:/# apt-get install ghc ... 1 upgraded, 28 newly installed, 0 to remove and 6 not upgraded. Need to get 52.0 MB of archives. After this operation, 378 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ... GHC is now ready to use! root@e9c2c3771b9e:/# which ghc /usr/bin/ghc root@e9c2c3771b9e:/# ghc --version The Glorious Glasgow Haskell Compilation System, version 7.6.3 Finally, download one of the Haskell sample sources files (we need to install wget first): root@e9c2c3771b9e:/# apt-get install wget root@e9c2c3771b9e:/# wget http://www.macs.hw.ac.uk/~hwloidl/Courses/F21DP/srcs/simples.hs Now you can start the interpreter, ghci, loading the simples.hs examples: root@e9c2c3771b9e:/# ghci simples.hs simples.hs:22:8: Could not find module `System.Random' Use -v to see a list of the files searched for. Oops, a Haskell library, used in these examples is missing. We search for it like this: root@433af75275d3:/tmp# apt-cache search ghc | fgrep random ... libghc-random-dev - Random number generator for Haskell libghc-random-doc - Random number generator for Haskell; documentation libghc-random-prof - Random number generator for Haskell; profiling libraries ... And install the libraries like this: root@433af75275d3:/tmp# apt-get install libghc-random-* Try again, start the interpreter and load the examples: root@433af75275d3:/tmp# ghci simples.hs GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( simples.hs, interpreted ) Ok, modules loaded: Main. *Main> This prompt shows that we are in the Main module of the GHC interpreter. You can now type in Haskell expressions to try some examples: *Main> fac 5 Loading package array-0.4.0.1 ... linking ... done. Loading package deepseq-1.3.0.1 ... linking ... done. Loading package old-locale-1.0.0.5 ... linking ... done. Loading package time-1.4.0.1 ... linking ... done. Loading package random-1.0.1.1 ... linking ... done. 120 *Main> sqs_even [1..10] [4,16,36,64,100] *Main> take 10 primes [2,3,5,7,11,13,17,19,23,29] *Main> quicksort (reverse (take 10 primes)) [2,3,5,7,11,13,17,19,23,29] *Main> writeSample "foo.txt" 1 9 13 *Main> myAction "foo.txt" 59 59 *Main> :edit foo.txt editor not set, use :set editor *Main> :set editor nano *Main> :edit foo.txt Ok, modules loaded: Main. Press CTRL-D to exit the interpreter. We are done with the docker-based exercises. The dowloaded file is in the current directory: root@e9c2c3771b9e:/# ls -la simples.hs -rw-r--r-- 1 root root 7845 Mar 5 17:45 simples.hs Next time you use the container, it will still be there. Press CTRL-D (or type exit) to leave the container. You are back to your top-level shell and you can check the status of containers like this: --(rigel[129](4.3))-- sudo docker ps If you want to continue working in the container, just type: sudo docker start -a -i e9c2c3771b9ede0af7819e74093d6f7758e65c6f31924e8bae53ecbcae029966