docker-compose intro
Setup
cp .env.example .env
- Edit
.env
variable forPORT
andIMAGE_VERSION
To build project
docker-compose build
To run project
docker-compose up
To run a project without terminal display (as a daemon)
docker-compose up -d
To stop project
docker-compose down
To stop project and destroy image and any volumes (total reset)
docker-compose down -v
To build an production version of your image
docker-compose -f docker-compose.yml -f docker-compose.prod.yml build
To push your official image version
docker-compose push
Docker Compose Checklist
- What base image do I start with?
- What environment variables does my project need?
- What do I need to separate from development and production environments?
- How am I starting the application in development vs production?
Best Practices
- Don't use third party images for production applications.
- Don't build sensitive files into your images.
- Use COPY over ADD to prevent command injection possibilities.
- Production images should be lean and have only what's needed to run your application.
- Create your docker-compose commands as npm scripts so you don't have to type them repeatedly. (But know what they do)