Docker-compose and new application workflow

Hello everyone

I’m having a bit of trouble with a local development workflow, when we’re building an app.

I’ve pasted the dockerfile and docker-compose.yml files we’re using below, and everything works as expected.

docker-compose up

everything is running, I can see the site and make code alterations successfully

what I’m struggling with now is adding a python module to the Dockerfile, and get that change to take effect in my container.

the only way I’ve found so far, and I’m having some different sorts of results doing this, add the new module to requirements.txt, then bring everything down

docker-compose down

then find the pcstudents_web image, and all it’s child images, delete them, then run

docker-compose up

sometimes that works ok, sometimes I’m blowing away my data volume, sometimes it doesn’t work at all

I’m pretty certain it’s because of the order I’m doing things, and/or not going them correctly either probably

Am I going down the right track here, or is there a much easier way to accomplish what I’m trying to do, or am i just doing it all wrong?

any hints or tips or links, greatly appreciated

docker-compose.yml
version: '2’
services:
pgdata:
image: cogniteev/echo
command: echo 'Data Container for PostgreSQL’
volumes:
- /var/lib/postgresql/data
pcstudents_db:
image: "postgres:9.4"
volumes_from:
- pgdata
expose:
- 5432
pcstudents_web:
build: .
command: python manage.py runserver 0.0.0.0:8000 --settings=pcstudents.settings.dev
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- pcstudents_db

Dockerfile
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install -r requirements.txt
ADD . /code/

Ah, just thought of something whilst reading my own post :slight_smile:

If I edit the requirements.txt, then

docker-compose run pcstudents_web pip install -r requirements.txt

I guess that should work

I could then save the edits to our git repo, push the changes, then the next person who builds from the start, with

docker-compose up

should get the new python modules

lets give that a spin

Right, I think I’ve got it

I’ve been missing a basic premise of docker

Just build the image again

docker-compose build pcstudents_web