-
Notifications
You must be signed in to change notification settings - Fork 14
Infra
Vagrant
You put code into environments
Run provisioning script onto VM =>
installs correct software (node.js version, user permissions, config)
Docker
You build your environment and can run it anywhere
Runs off of containers.
Dockerfile builds a docker image.
Docker image: complete app code that will sit on top of a machine (you don't store the machine on the image)
Run docker image in a container.
Push that image to Docker Hub (or others)
Any other machine can run your IMAGE. [docker run myProjectImage]
-> Since the image contains the entire image you don't need to install any software on that new machine
-> In other words, no need to install npm, node.js, etc.
-> Cloud Clusters: All the computers to act as one; share resources. Spin up containers all run in the cluster.
nginx: Can spin up an nginx container and load balance the containers and provide a port to allow one to
access the app.
Python & Docker
Dockerfile
: Re
Docker container interacts directly with host kernel.
Spin up more processes? Spin up more containers.
Docker host?
The image contains everything (code, modules, dependencies, etc.)
Docker build
: Dependencies, nginx, wsgi, etc.
Docker run
: Makes instance of the app, creates a container (running instance of the app)
Docker engine. Call the Dockerfile
.
FROM python:3.4
# Set PYTHONUNBUFFERED so output is displayed in the Docker log
# Helps out put logs in console
ENV PYTHONUNBUFFERED=1
# app (service) is exposed on port 8000
EXPOSE 8000
# here is the location of the django app itself
WORKDIR /usr/src/app
# Install dependencies
# takes req.txt and copies it into the Docker image
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Copy the rest of the source code into app dir
# copy all the source code
COPY . /usr/src/app
# Run the app: run django migrations & runserver
# not good for production practices (using django test server).
CMD ["./run_app.sh"]
docker build -t nameApp
# -t: tag Docker image with a name
Container: chained images
docker run -p 8002:8000 nameApp
We now have this IMAGE.
docker run -d -p 8002:8000 nameApp
docker logs
=> what has been stdout in the container
kill it docker stop logger
all the components of the app in a yml config file.
web:
build: .
links:
- 'db' #IMPORTANT!
ports:
- '8000:8000'
environment:
- 'DATABASE_HOST=db'
- 'DATABASE_NAME=postgres'
- 'DATABASE_USER=postgres'
- 'DATABASE_PASSWORD=postgres'
db:
image: postgres:9.4 $ could do docker run -d --name db postgres9.4 (docker log db => print logs)
we want 2 containers: a web container and a pg container.
Docker will spin up two containers: db & web
You need to link these two in order to actually use the db.
^ It's running on pg!
docker-compose up
: Runs the yml file
docker-compose build
: Rebuild them