Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building docker images from a source directory using different dockerfiles

Tags:

My goal is to build several different docker images , from the same source code.

i have my ./src folder (node.js project). inside ./src i have first.dockerfile and second dockerfile.

for building the the project i use this standard command line

sudo docker build -t doronaviugy/myproject . 

This works with no problems using the default Dockerfile

I'm trying to build it from a specific dockerfile using the line

sudo docker build -t doronaviguy/myproject  - <   first.docker 

this line works, but now path doesn't being copy inside the image

#Inside the Dockerfile ADD . /src 

I think i understand how to specify a dockerfile argument, but i need to specify a direcotry argument to be copied inside the docker image.

Thanks a lot.

like image 537
doron aviguy Avatar asked Apr 02 '15 09:04

doron aviguy


People also ask

How to build an image using a dockerfile?

The basic syntax used to build an image using a Dockerfile is: docker build [OPTIONS] PATH | URL | - To build a docker image, you would therefore use: docker build [location of your dockerfile]

How to use an older version of Docker in a build?

If you have to use an older version of Docker, you'll need to use some scripting to copy your specific Dockerfiles to Dockerfile at the root of the build context before calling docker build. Thanks , i did to try to use the -f argument , but with no success, and then i noticed i had to upgrade my docker version to 1.5 .

How to change the Docker build context in a pipeline?

This pipeline checks out the source code of the repository and then builds a dockerfile found at the subfolder docker while still keeping as Docker context the root directory. You could also change the Docker build context by editing the working_directory property.

How do I check the content of a dockerfile?

You can check the content of the file by using the cat command: If you are already in the directory where the Dockerfile is located, put a . instead of the location: docker build . By adding the -t flag, you can tag the new image with a name which will help you when dealing with multiple images: docker build -t my_first_image .


1 Answers

Since Docker 1.5, you can use the -f argument to select the Dockerfile to use e.g:

docker build -t doronaviugy/myproject -f dockerfiles/first.docker .

If you use stdin to build your image ( the - < first.docker syntax), you won't have a build context so you will be unable to use COPY or ADD instructions that refer to local files.

If you have to use an older version of Docker, you'll need to use some scripting to copy your specific Dockerfiles to Dockerfile at the root of the build context before calling docker build.

like image 117
Adrian Mouat Avatar answered Nov 15 '22 13:11

Adrian Mouat