skip to Main Content

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 "$sptpath/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

2

Answers


  1. 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");
    
    Login or Signup to reply.
  2. @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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search