Getting started with Rakudo Perl 6 in a Docker container

Note! This site is about Perl 6.
If you are looking for a solution for Perl 5, please check out the Perl 5 tutorial.

Download and Install Docker

Launch the Docker daemon


docker run -it rakudo-star

This might take some time as it needs to download the Rakudo Docker image. The output will look something like this:

Unable to find image 'rakudo-star:latest' locally
latest: Pulling from library/rakudo-star
693502eb7dfb: Already exists
081cd4bfd521: Pull complete
5d2dc01312f3: Pull complete
e090aa29a3ec: Pull complete
c3439586dbe8: Pull complete
Digest: sha256:eac1ce2634c62857ee7e5e3f23b2156206edef779da47c08c4ac508f905ca60d
Status: Downloaded newer image for rakudo-star:latest
To exit type 'exit' or '^D'

Then you can type in your Perl 6 code:

> say 'Hello Rakudo'
Hello Rakudo

This Rakudo runs on a Linux box. Let's look around:

The Current Working Directory can be accessed via the $*CWD variable:

> say "$*CWD"

We can also list all the directories:

> for dir() -> $f { say "$f" }

We can check out the version of Perl:

> $*PERL
Perl 6 (6.c)

and the location of the current Perl 6 executable:


If we type exit we will leave the Perl 6 interactive shell and with that we'll leave the Docker Image and get back to the prompt of our host operating system.

Perl 6 from terminal

If we run the following Docker command:

docker run -it --name rakudo -v $(pwd):/opt rakudo-star bash

(On Windows, you will need to replace $(pwd) the path to the current directory.)

it will launch a Docker container called "rakudo" based on the "rakudo-star" image. It will map the current working directory of the host operating system to /opt inside the container, and finally, instead of launching the interactive shell, it will launch a regular shell running bash.

You'll see a prompt like this one:


You can execute subset of the regular Unix/Linux Bash commands such as "pwd" and "ls". If you type "ls -l opt/" you'll see the content of the directory on the host OS. If you need other command, you can install them using apt-get. In order for that to work properly first we need to update the package list:

root@7d03b913aeca:/# apt-get update

0% [Working]
Get:1 jessie/updates InRelease [63.1 kB]
Ign jessie InRelease
Get:2 jessie-updates InRelease [145 kB]
Get:3 jessie Release.gpg [2373 B]
Get:4 jessie Release [148 kB]
Get:5 jessie/updates/main amd64 Packages [453 kB]
Get:6 jessie-updates/main amd64 Packages [17.6 kB]
Get:7 jessie/main amd64 Packages [9049 kB]
Fetched 9878 kB in 15s (644 kB/s)
Reading package lists... Done

Install less, make, and gcc

The Linux-box is so bare-bones that less is not installed and we'll need it to use p6doc. In addition we'll need make and gcc for some of the additional installation.

In order to check what is the name of the package that contains the less command type in:

# apt-cache search less| grep ^less

less - pager program similar to more

Then to install it type in:

# apt-get install -y less

You can verify that the installation succeeded by typing

# which less


In order to install make and gcc type in:

# apt-get install make gcc

First Perl 6 script

Using your tools on the host Operating system, create a file called in the directory where you launched the Docker container, and add the following two lines:

use v6;
say "Hello from Perl 6";

Now you can run the script by typing in the following:

perl6 opt/

@1fa71fb0cfcb:/# perl6 opt/
Hello from Perl 6

Getting Help with p6doc

p6doc is the command-line tool to read documentation of Perl 6. Try it!

# p6doc
# p6doc -l
# p6doc io

Alternatively, visit The Perl 6 documentation.

Installing modules

The CPAN of Perl 6 is more limited than the CPAN of Perl 5, but a lot of things that are implemented in Perl 5 modules are already available in the core of Perl 6.

In any case you can find 3rd-party modules for Perl 6.

You can install modules using zef. For example we can install Terminal::Readsecret in order to read passwords on the command-line without echoing back to the screen:

# zef install Terminal::Readsecret

===> Searching for: Terminal::Readsecret
===> Building: Terminal::Readsecret:ver('0.0.2')
===> Building [OK] for Terminal::Readsecret:ver('0.0.2')
===> Testing: Terminal::Readsecret:ver('0.0.2')
t/01-basic.t ..... ok
t/02-password.t .. ok
All tests successful.
Files=2, Tests=2,  3 wallclock secs
Result: PASS
===> Testing [OK] for Terminal::Readsecret:ver('0.0.2')
===> Installing: Terminal::Readsecret:ver('0.0.2')

Using Terminal::Readsecret

Create a small script copying on the example from the README of Terminal::Readsecret.

Save this content as in the directory where you launched the Docker container:

use Terminal::Readsecret;
my $password = getsecret("password:" );
say "your password is: " ~ $password;

Then run

perl6 opt/

Exit and restart the container

Now you can type exit (this is the Unix exit command) which will leave and close the Docker container.

Running the container again

If you try to run the same container again using the same command:

# docker run -it --name rakudo -v $(pwd):/opt rakudo-star bash

it will fail with a message like this:

docker: Error response from daemon: Conflict. The container name "/rakudo" is already in use by container 7d03b913aeca4c45e386b2e73d060428d7e3b07ab0b7e56a8c6f8eb0b2eb582a. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.

That's because we've already created a container called "rakudo". We could remove it or we could create a new container with another name, but then we would need to start the installations again. Instead of that we could use the existing container:

# docker start rakudo && docker attach rakudo

It will print "rakudo" and then it will seem to hanged without showing a prompt. You have to press ENTER again in order to get to the prompt.

With this you are back to your same prompt, with all the installed stuff. With the mounting of your directory to /opt/ and even with your Bash History.

Enjoy Perl 6 in your Docker!

The Perl 6 Tricks and Treats newsletter has been around for a while. If you are interested to get special notification when there is new content on this site, it is the best way to keep track:
Full name:
This is a newsletter temporarily running on my personal site ( using Mailman, till I implement an alternative system in Perl 6.
Gabor Szabo
Written by Gabor Szabo

Published on 2017-03-25


In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus
Suggest a change
Elapsed time: 2.4534060

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.