SURVIVING ENVIRONMENT HELL WITH DOCKER Docker provides reproducible environments across many platforms so software can run as expected. It abstracts away package managers, network interfaces and so much more. I guess Docker can be viewed as some sort of operating system. ARCHITECTURE The Docker ecosystem is structured like so: A repository holds many Docker images; a registry serves Docker images; a Docker image is essentially a file system and configuration telling the Docker binary how to set things up for the environment; a container is a runtime instance of the image (like a class vs object). An image is composed of layers, which are just differences in the file system recorded. The differences that it watches for are done by the ADD/COPY/RUN commands. OPERATIONS Docker operates on images and containers, so these commands will be common: * `docker info` * `docker build -t ` to build an image. * `docker run ` to run an image. * `docker image ` * `docker container ` `docker login` is useful for getting access to other remote registries other than Docker Hub (Docker Company's registry). ENVIRONMENT CONFIGURATIONS To configure an environment, a `Dockerfile` is used, which is simple for the most part. Below is an example of the most typical commands you'd use inside one: # Use an official Python runtime as a parent image # FROM *MUST* be the first command in all Dockerfiles. FROM python:2.7-slim # You can use a MAINTAINER command too, for support contact MAINTAINER inbox@leefallat.ca # Set the working directory to /app WORKDIR /app # Copies between the user's file system and the image. # Copy the current directory contents into the container at /app COPY . /app # There is also an ADD command, and it works like COPY but it is 100x more # powerful and so it is somewhat dangerous to use. It can copy things from # remote sources and does unpacking and probably other things. Review the # documentation before using it. # Runs arbitrary commands for setup. RUN will commit file system changes to the # image file. # Install any needed packages specified in requirements.txt RUN pip install --trusted-host pypi.python.org -r requirements.txt # For networking - very easy as you see! # Make port 80 available to the world outside this container EXPOSE 80 # Define an environment variable ENV NAME World # There *MUST* only be one CMD command in a Dockerfile. # This is essentially to start your software. # Run app.py when the container launches CMD ["python", "app.py"] # You can also use ENTRYPOINT which is a bit better - it lets you pass # parameters to your program within the container. :) You can only have one of # these too.