Home > other >  Create a directory using Perl Script in docker
Create a directory using Perl Script in docker

Time:05-21

I have a simple Perl script as below, which creates a directory logs under /ops/dim/foo. This Perl script does not create the directory when running in a Docker container.

makedir-script.pl:

#!/usr/bin/perl 
use warnings;
use strict;

my @i = (1..9);

for(@i){
    print("$_: Hello, World!\n");
}
my $sptpath = "/ops/dim/foo";
mkdir "$scriptpath/logs" unless(-d "$sptpath/logs");
print("Opening POD created logs folder!\n");

docker file:

FROM ubuntu:16.10
WORKDIR /ops/dim/foo
COPY makedir-script.pl ./
CMD  perl makedir-script.pl

CodePudding user response:

Your script fails because $scriptpath isn't set to anything.

It tries to do mkdir "$scriptpath/logs" because /ops/dim/foo/logs doesn't exist.

You probably want to use $sptpath instead, so your statement becomes

mkdir "$sptpath/logs" unless(-d "$sptpath/logs");

CodePudding user response:

@Hans Kilian answer is fine, but if you only need to create a folder, is easy to do in your Dockerfile. Just like this:

RUN mkdir -p /ops/dim/foo/logs
  • Related