0

Hey guys so I've spend the past few days really digging into Docker and I've learned a ton. I'm getting to the point where I'd like to deploy to a digitalocean droplet but I'm starting to wonder about the strategy of building/deploying an image.

I have a perfect Dev setup where I've created a file volume tied to my app.

docker run -d -p 80:3000 --name pug_web -v $DIR/app:/Development test_web

I'd hate to have to run the app in production out of the /Development folder, where I'm actually building the app. This is a nodejs/express app and I'd love to concat/minify/etc. into a local dist folder ane add that build folder to a new dist ready image.

I guess what I'm asking is, A). can I have different dockerfiles, one for Dev and one for Dist? if not B). can I have if statements in my docker files that would do something like... if ENV == 'dist' add /dist... etc.

I'm struggling to figure out how to move this from a Dev environment locally to a tightened up production ready image without any conditionals.

Greg Thompson
  • 886
  • 4
  • 12
  • 31

2 Answers2

3

I do both.

My Dockerfile checks out the code for the application from Git. During development I mount a volume over the top of this folder with the version of the code I'm working on. When I'm ready to deploy to production, I just check into Git and re-build the image.

I also have a script that is executed from the ENTRYPOINT command. The script looks at the environment variable "ENV" and if it is set to "DEV" it will start my development server with debugging turned on, otherwise it will launch the production version of the server.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
  • Thanks, is this a public image or can you share your dockerfile? Also how are you checking out code in the dockerfile? do you install git and fetch it in the container? Lastly, how do you set your ENV? – Greg Thompson Jun 12 '15 at 18:35
  • 1
    I check the code out with git, yes. `docker run -e ENV=DEV ...` will set the variable to launch the development server. It's actually part of the book I'm writing, if you want to see it: http://shop.oreilly.com/product/0636920035671.do (Apologies to everyone else for the plug) – Adrian Mouat Jun 12 '15 at 19:48
  • no, thanks so much. My last question is, do you build the production ready image with the code in it? So, if git is housing all of your dev code, do you create a grunt/gulp task etc. that will ready all of your code for production, drop it in a folder, add it to the image and build? Or do you pull code to container and build your production code there? – Greg Thompson Jun 12 '15 at 22:24
  • 1
    To be honest, it's just some python code in the book, so there isn't any "ready for production". But yes, I would use Docker to build my code, if that's the question. Some people have separate Dockerfiles to build and run their code. – Adrian Mouat Jun 13 '15 at 10:32
0

Alternatively, you can avoid using Docker in development, and instead have a Dockerfile at the root of your repo. You can then use your CI server (in our case Jenkins, but Dockerhub also allows for automated build repositories that can do that for you, if you're a small team or don't have access to a dedicated build server.

Then you can just pull the image and run it on your production box.

Alex Lynham
  • 1,318
  • 2
  • 11
  • 29