Skip to content

Instantly share code, notes, and snippets.

@dmehrotra
Created November 2, 2016 18:15
Show Gist options
  • Save dmehrotra/023ac72e255a78b44fcda50b46838bed to your computer and use it in GitHub Desktop.
Save dmehrotra/023ac72e255a78b44fcda50b46838bed to your computer and use it in GitHub Desktop.
Docker Shit for Refugee School
Docker
Slide 1
There's only a single operating system running. That operating system is just carved up into isolated little spaces.
A container is a self-contained sealed unit of software. It has everything in it that is needed to run that code.
Docker uses bridges to create virtual networks inside your computer
Docker is a program written in Go - > Kernels run directly on your hardware
its job is to manage features of the kernel ( networking disc allocation etc )and use these features to build the concept of containers and images….
docker uses control groups to group process together to give them an idea of being grouped together in their own little worldSlid
it uses copy on write file systems to build the idea of images to say, you have this image, it doesn’t change but you can run shit on top of it.
docker is divided into a client and server…
the client communicates over a network and sends messages to the docker server to say, start a container
eg:
the client program connects to the socket,
sends commands to the docker server program
and creates and deletes containers.
Other:
docker uses namespaces to contain networks so you have one set of address for one container and another for another….
ethernet layer moves little frames of data in a local area
above that you have ip layer and thats how data moves between networks and between systems in different parts of the world
routing is how packets get into and out of networks
Slide 2
The communicatotion between containers happened by explicitly assigning ports
so ideally what we ( KIRON && Andy and I ) would need is an orchestration systems to:
start containers and restart them if they fail and allow them to find their necessary linked processes..
eg:
Kubernetes
Amazons EC2 container services
The last thing i’ll say is that it may be tempting to just have one or two docker images that could help speed along getting development and server dependencies set up and synced.
While this is great it wouldn’t be leveraging the power of docker, which provides a really cool way to implement micro services….
============IMPORTANT COMMANDS=============
. '/Applications/Docker/Docker Quickstart
Terminal.app/Contents/Resources/Scripts/start.sh'
docker-machine status default
eval $(docker-machine env default)
have to start kitematic before docker
image: minimum files to do an action
docker run = takes an image turns it into a container thats running something useful
docker run -ti ubuntu:latest bash
ubuntu:latest = dockerrepo:tag
bash = run bash shell
ti = terminal interactive
zor some reason every new terminal has to be run with:
bash -c "clear && DOCKER_HOST=tcp://IP:2376 DOCKER_CERT_PATH=/Users/Mehrotra/.docker/machine/machines/default DOCKER_TLS_VERIFY=1 /bin/zsh”
docker ps shows the image and the command thats running in the container
image runs container…container resets to default everytime you run…
stopped container: you have to find the old container to go see files you changed???
docker ps -l is the last container
docker ps -a is all containers
docker commit takes containers and makes images out of them
exit container
get container id
docker commit container_name my_image_name
returns big fucking name
docker tag big fucking name my-image
docker run -ti my-image bash
docker run—rm whatever will remove container
docker run -d will run the process in a detached state
docker attach name
docker cntrl pq detaches but leaves it running
docker exec -ti name…will put you in the same container
container exits when process is done
docker logs container name
docker run —name example -d ubuntu:latest bash -close /etc/pasword”
docker-machine ip
list images
docker images
echo server
docker run —rm -ti -p 45678:45678 -p 45679:45679 —name echo-server ubuntu:latest bash
======FUN NETCAT COMMUNICATION BETWEEN CONTAINERS=============
in container run nc -lp 45678 | nc -lp 45679
in new terminal nc docker ip addy
===============
1. group services into private networks by explicitly exposing ports of a container to other containers
=======================
docker run —rm -ti -p (outside)45678:(inside)45678 -p 45679:45679 —name echo-server ubuntu:latest bash
docker run —rm -ti -p 45678:45678 -p 45679:45679 —name echo-server ubuntu:latest bash
=======================
PRIVATE NETWORKS:
a network of containers that speak to each other on your system.
programs in containers are isolated from internet by default
docket network create example
=================
docker run —rm -ti —net=example —name server ubuntu:14.04 bash
docker run —rm -ti —net=example —name client ubuntu:14.04 bash
from -> to
docker run -p 127.0.0.1:12345:12345/tcp
***run a container that listens for connections from your local machine on a port and
forward it to that port/tcp inside the container
==============SHARING WITH HOST
shared folder with host:
sharing data between host (docker virtual env) and containers within it.
docker-machine ssh
mkdir whatever
docker run -ti -v /home/docker/whatever:/shared-data ubuntu:latest bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment