Docker allows the creationg of small Linux containers that can make building environments and deploying applications easy. Let's see how can we use Rakudo with a Docker image.
There is a Docker image for Rakudo Star we can easily us to develop Perl 6 code.
$ docker run rakudo-star perl6 -e 'say "Hello!"'
Create a file locally on your host system called "hello_world.pl" with the following content:
use v6; say "Hello from Perl 6";
and then run it as:
docker run -v $(pwd):/opt rakudo-star perl6 /opt/hello_world.pl
The flag -v $(pwd):/opt will map the current working directory of your host machine to the /opt directory of the Docker container. If you have the "hello_world.pl" file in the current directory then it will be accessible by the container as "/opt/hello_world.pl".
If you are running on an MS Windows machine then you'll probably write this:
docker run -v %cd%:/opt rakudo-star perl6 /opt/hello_world.pl
If you'd like to explore Perl 6 using the interactive shell you can type the following:
docker run -it rakudo-star
It will run Perl 6 and show you a prompt:
To exit type 'exit' or '^D' >
At this point you can type in some Perl 6 code:
say "hello" hello >
Once you are done, you can leave the shell and close the Docker container using:
Docker will leave behind the exited containers. You can list them using:
docker ps -a
You can remove them with
docker rm $(docker ps -a -q)
Alternatively, include the --rm flag in the command line options of docker run and then the containers will be removed when they are exited.
$ docker run --rm rakudo-star perl6 -e 'say "Hello!"'
$ docker run --rm rakudo-star perl6 -v
Published on 2018-06-07