FROM python:2.7
# Install Python packages
RUN pip install gunicorn Flask
# Add our own code to the image
ADD . /code
# Run the application
CMD ["bin/start.sh"]
myapi:
build: .
volumes:
- .:/code
ports:
- 8080:80
environment:
- DB_URL=postgresql://user:pw@database:5432/mydb
links:
- database
database:
image: postgres:9.4
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pw
# Build and start all containers
$ docker-compose up -d
# List running containers
$ docker-compose ps
Name Command State Ports
------------------------------------------------------------------
myapi_myapi_1 bin/start.sh Up 0.0.0.0:8080->80/tcp
myapi_db_1 postgres Up 5432/tcp
repositories ├── myapi │ ├── docker-compose.yml │ ├── Dockerfile │ └── ... └── mywebapp ├── docker-compose.yml ├── Dockerfile └── ...
repositories ├── myapi │ └── ... ├── mywebapp │ └── ... └── myenvironments ├── local │ └── docker-compose.yml ├── develop │ └── docker-compose.yml ├── test │ └── docker-compose.yml └── production └── docker-compose.yml
myapi:
build: ../../myapi
...
mywebapp:
build: ../../mywebapp
...
database:
image: postgres:9.4
...
elasticsearch:
image: elasticsearch:2.3
...
nginx:
image: nginx:1.8
...
# docker-compose.yml
jenkins:
image: jenkins
links:
- registry
volumes:
- /home/jenkins/:/var/jenkins_home
ports:
- "8080:8080"
registry:
image: registry:2.0
volumes:
- /home/registry:/tmp/registry-dev
ports:
- "5000:5000"
# Build script executed by Jenkins
# Build and run tests
docker-compose build
docker-compose run myapi nosetests
# Where to push image
IMAGE_LOCATION=localhost:5000/myapi:master-$BUILD_NUMBER
# Tag and push the image to our Docker registry
docker tag myapi:latest $IMAGE_LOCATION
docker push $IMAGE_LOCATION
But this is often "good enough" for non-critical systems, or during the initial project phase