Home > front end >  Using regex in Docker COPY for digits
Using regex in Docker COPY for digits

Time:04-27

Im trying to copy a file in docker with below format

database-20.2.1.zip 

I have tried using something like below, but it does not seems to work

COPY databse- ([0-9]). ([0-9]). ([0-9]).zip /docker-entrypoint-initdb.d/database.zip

Is this something that can be done in docker copy ?

CodePudding user response:

Dockerfile COPY uses shell globs, not regular expressions. The actual implementation uses the Go filepath.Match syntax. That syntax doesn't allow some of the combinations that regular expressions do: you can match any single digit [0-9], or any number of characters *, but not any number of digits.

Depending on how strict you want to be about what files you'll accept and how consistent the filename format is, any of the following will work:

COPY database-[0-9][0-9].[0-9].[0-9].zip ./database.zip
COPY database-*.*.*.zip ./database.zip
COPY database-*.zip ./database.zip

In all cases note that the pattern can match multiple files in the build context. If the right-hand side of COPY is a single file name (not ending with /) but the glob matches multiple files you will get a build error. In this case that's probably what you want.

  • Related