简体   繁体   中英

Development environment with Docker and deploying to AWS Elastic Beanstalk

I'm writing a PHP application and want the development environment to be a Docker container. To do that, I've created a Dockerfile in the root of my project that installs all the packages required by my application, copies over configuration files to the container and then installs my application.

This is working fine, but now I need to tell my PHP application what environment it's in, either development or production . This is also easy, I can just add this to my Dockerfile :

ENV environment development

Now when I build my image, my PHP application runs in development mode. Great, now I can build my application inside a Docker container!

But what happens when I want to deploy this application to a production server (AWS Elastic Beanstalk, to be specific)? If I've specified in my Dockerfile that the environment is development , will my application not run in development mode when it's deployed to Elastic Beanstalk?

Setting the environment variable is a good way to do it; however, by doing it in the Dockerfile you're setting it for any containers derived from that image. What you really want to do is set it on a container-by-container basis. The way to do that is by setting it when you run the container:

For development:

docker run --env environment=development my-image

And for production:

docker run --env environment=production my-image

Note that this will work even if you set the environment variable in your Dockerfile - variables set with docker run --env will override the values set in the Dockerfile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM