Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Docker ADD command for multiples files

Tags:

regex

docker

I want to copy some files to my images and I wan to use the ADD command. I read in the Docker documentation about regular expression for ADD, but I don't know what kind of expression can I use?

I want something like this

FROM registry:5000/ubuntu:14.04
MAINTAINER Me

# some stuffs 

ADD Sources/{file1,file2,load_file} /etc/Sources/

# more stuffs

Note: the expression is wrong but I did it to show you what I expect from the ADD command. (I did it thinking in shell regular expressions).

So, How can I do that? I can not access to the link filepath.Match. If anyone have these rules, please let me know?

Update

I am using this Docker docs reference

I am using this version:

Client version: 1.3.0
Client API version: 1.15
Go version (client): go1.3.3
Git commit (client): c78088f
OS/Arch (client): linux/amd64
Server version: 1.3.0
Server API version: 1.15
Go version (server): go1.3.3
Git commit (server): c78088f
like image 200
Robert Avatar asked Oct 27 '14 16:10

Robert


People also ask

What does add command do in Dockerfile?

ADD command is used to copy files/directories into a Docker image. It only has only one assigned function. It can also copy files from a URL. Its role is to duplicate files/directories in a specified location in their existing format.

Can you have multiple Docker files?

As Kingsley Uchnor said, you can have multiple Dockerfile , one per directory, which represent something you want to build.

Can I run multiple commands in Dockerfile?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.


2 Answers

The ADD command and COPY both allow Golang's filepath.Match wildcards

You can find a number of examples in the test code for Go: https://golang.org/src/pkg/path/filepath/match_test.go

Rules reproduced here for those in China who can't access Google/golang.org:

    '*'         matches any sequence of non-Separator characters
    '?'         matches any single non-Separator character
    '[' [ '^' ] { character-range } ']'
                character class (must be non-empty)
    c           matches character c (c != '*', '?', '\\', '[')
    '\\' c      matches character c

character-range:
    c           matches character c (c != '\\', '-', ']')
    '\\' c      matches character c
    lo '-' hi   matches character c for lo <= c <= hi
like image 120
Andy Avatar answered Oct 25 '22 22:10

Andy


Usually, you would end up putting all the relevant files into a sub-directory, and then just ADD that directory, to bring them into the image.

like image 29
Alister Bulman Avatar answered Oct 25 '22 22:10

Alister Bulman