Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.
For the best experience please use the latest Chrome, Safari or Firefox browser.
Has been around since GIFs were popular. Loves front-end development, learning, sharing, and beer (a bit too much).
Why you should be using
Your software stack can be quite complex
And your team can be very diverse and specialized
This can lead to a fractured development process
And this is where Docker shines!
It can provide a group of containers with all the services required by the project, delivering a development environment that everyone in the team can benefit from.Docker can help you reduce PC bloat!
How can teams, integrate Docker into their Development Process?
docker run -it --rm \ --user "$(id -u):$(id -g)" \ -v "$PWD":/usr/src/app \ -w /usr/src/app \ django django-admin.py startproject project_name
We can define our environment with the help of these two types of files:
Defines a container and sets it in an known state.
For example, install a service and configure its default values.
Simplifies the startup process of all the containers, the ports bindings, and the disk volumes to synchronize locally.
FROM django:1.9.2 ADD ./requirements.txt /usr/src/app/requirements.txt WORKDIR /usr/src/app RUN pip install -r requirements.txt ADD ./manage.py /usr/src/app/manage.py
hello_django_app: build: . volumes: - ./hello_django:/usr/src/app/hello_django ports: - 8000:8000 command: python manage.py runserver 0.0.0.0:8000
docker-compose build docker-compose up
hello_django_app: build: . volumes: - ./hello_django:/usr/src/app/hello_django ports: - 8000:8000 command: sh ./init.sh links: - hello_django_db hello_django_db: image: postgres:latest ports: - 5432:5432 environment: - POSTGRES_DB=hello_django_db extends: file: env-vars.yml service: hello_django_env_vars
hello_django_app: build: . volumes: - ./hello_django:/usr/src/app/hello_django ports: - 8000:8000 command: sh ./init.sh links: - hello_django_db hello_django_db: image: postgres:latest ports: - 5432:5432 environment: - POSTGRES_DB=hello_django_db extends: file: env-vars.yml service: hello_django_env_vars
hello_django_app: build: . volumes: - ./hello_django:/usr/src/app/hello_django ports: - 8000:8000 command: sh ./init.sh links: - hello_django_db hello_django_db: image: postgres:latest ports: - 5432:5432 environment: - POSTGRES_DB=hello_django_db extends: file: env-vars.yml service: hello_django_env_vars
# env-vars.yml
hello_django_env_vars:
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=super-secret-password
# settings.py from os import environ # ... DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'hello_django_db', 'USER': environ.get('HELLO_DJANGO_DB_ENV_POSTGRES_USER'), 'PASSWORD': environ.get('HELLO_DJANGO_DB_ENV_POSTGRES_PASSWORD'), 'HOST': environ.get('HELLO_DJANGO_DB_PORT_5432_TCP_ADDR'), 'PORT': environ.get('HELLO_DJANGO_DB_PORT_5432_TCP_PORT'), } }
docker-compose run hello_django_app printenv
* The container must be up when running this command
hello_django_app: build: . volumes: - ./hello_django:/usr/src/app/hello_django ports: - 8000:8000 command: sh ./init.sh links: - hello_django_db hello_django_db: image: postgres:latest ports: - 5432:5432 environment: - POSTGRES_DB=hello_django_db extends: file: env-vars.yml service: hello_django_env_vars
# init.sh
RUN until netcat -z -v localhost 5432; do
echo "$(date) - waiting for postgres...";
sleep 1;
python ./manage.py makemigrations
python ./manage.py migrate auth
python ./manage.py migrate
python ./manage.py runserver 0.0.0.0:8000
docker-compose run hello_django_app python manage.py createsuperuser
The data inside the DB container is stored there as long as the container is not rebuilt. If you need the data to persist, you can store it locally.
# ./docker-compose.yml hello_django_db: image: postgres:latest volumes: - ./db-data:/var/lib/postgresql/data ports: - 5432:5432 environment: - POSTGRES_DB=hello_django_db extends: file: env-vars.yml service: hello_django_env_vars
We can add a container that provides Bower, SASS, and/or Gulp, etc.
# ./docker-compose.yml node: image: digitallyseamless/nodejs-bower-grunt:0.12 volumes: - ./bower.json:/data/bower.json - ./.bowerrc:/data/.bowerrc - ./hello_django/static/vendors:/data/hello_django/static/hello/vendors
And running it as such:
docker-compose run node bower install
Questions: @rene_olivo