user5526811
user5526811

Reputation:

Using two docker files - dev and prod

Hei,

I'm using a docker file to create a image for my production code, which doesn't include the source code:

FROM         node:latest

MAINTAINER   Fatima Alves

COPY         ./dist            /mya-app/dist/
COPY         ./s3options.json  /mya-app/
COPY         ./node_modules    /mya-app/node_modules
WORKDIR                        /mya-app

ENTRYPOINT   ["node", "./dist/"]

And now i would like to create a image to work in my machine, a devimage. In this case, the folder src must be included, and the ENTRYPOINT would be ["node", "./dist"].

Is it possible to include this in my Dockerfile, or do i need two files, one for dev and other for prod?

Thanks in advance!

Upvotes: 0

Views: 212

Answers (2)

Eugen Mayer
Eugen Mayer

Reputation: 9934

The answer above is not entirely correct.

You should use it this ways

docker-compose -f docker-compose.yml -f docker-compose-dev.yml up

while docker-compose.yml is the production one. The point here is, only adding overrides in the .dev file, so e.g. add volume shares to mount code, add some ENV variables like RAILS_ENV=development, expose some ports for development.

What you do not want to do is duplicating the production file though, since you want to stick to the production as close as possible. So in the end, the files are merged, while the file to the right has higher weight / overrides values in of the left file.

If the setting is a hashmap like ports/volumes, the settings are deep-merged, so just added.

If you are using a MAC, you can have a look at http://docker-sync.io - with docker-sync-stack start you get fast volume shares and also -dev file support out of the box - see https://github.com/EugenMayer/docker-sync-boilerplate/tree/master/rsync - here you see a dev / production file as an example

Upvotes: 2

homelessDevOps
homelessDevOps

Reputation: 20736

As far as i know you need 2 Dockerfiles. In my environments i use Dockerfile and Dockerfile.dev

docker build -f dockerfile.dev -t code:dev .

or

docker built -t code:prod .

Upvotes: 1

Related Questions