by Rob Richardson
Rob Richardson is a software craftsman building web properties in ASP.NET and Node, React and Vue. He's a frequent speaker at conferences, user groups, and community events, and a diligent teacher and student of high quality software development. You can find this and other talks on https://robrich.org/presentations and follow him on twitter at @rob_rich.
DEMO:
Hello Docker
"Docker: VM++"
ideal platform for dev & ops
ideal platform for dev & ops
Like any good story,
we've started in the middle ...
Docker is an ecosystem around Container Virtualization
Light-weight kernel virtualization
A suite of command-line tools for creating, running, and managing containers
Source: http://www.zdnet.com/article/what-is-docker-and-why-is-it-so-darn-popular/
Containers virtualize and share the host kernel
Containers must run on the kernel for which they were built:
Download: https://robrich.org/slides/welcome-to-docker/docker-ecosystem.pdf
FROM node
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
ENV NODE_ENV production
ENV PORT 3000
EXPOSE 3000
CMD ["npm", "start"]
FROM ...
RUN ...
COPY ...
CMD [ ... ]
Each line in the Dockerfile creates a layer
Layer is isomorphic
Layer hash is SHA256 of content and parent hash
See https://gist.github.com/aaronlehmann/b42a2eaf633fc949f93b#id-definitions-and-calculations
Source: https://docs.docker.com/engine/userguide/storagedriver/aufs-driver/
Only downloads each layer to disk once
because layers don't change
Volumes are a pointer in the container
saved to a folder on the host
In Dockerfile:
VOLUME ["/data"]
Starting container
docker run -v $(pwd):/data imagename
Download: https://robrich.org/slides/welcome-to-docker/docker-ecosystem.pdf
build dockerfile into image:
docker build .
list images:
docker image list
remove an image:
docker image rm myimage
run the image as a container
docker run imagename
list containers:
docker container list
stop container:
docker stop containername
remove container:
docker rm containername
DEMO:
Craft Dockefile, build image, run container
What did it do?
Want another server?
"docker run" it again
1 container is 1 process
docker run -p 80:5000 imagename:version
Port 80 outside maps to port 5000 inside
docker run -v $(pwd):/data imagename
Symling the host's current directory
to the container's /data folder
docker run imagename /bin/bash
Ignore CMD instructions and run this instead
docker logs containername
Gets all logs sent to stdout and stderr
Consider piping these to promethius or ELK
Download: https://robrich.org/slides/welcome-to-docker/docker-ecosystem.pdf
Tag the image
docker image tag myimage username/imagename:1.2.3
Login to Docker Hub
docker login
Push the image to Docker Hub
docker push username/imagename:1.2.3
Download the image
docker pull username/imagename:1.2.3
Download image layers and start container
docker run username/imagename:1.2.3
Download: https://robrich.org/slides/welcome-to-docker/docker-ecosystem.pdf
Features:
version: '3'
services:
web:
build: .
ports:
- "80:5000"
volumes:
- logvolume01:/var/log
links:
- redis
redis:
image: redis
volumes:
logvolume01: {}
docker-compose
commandsBuild all the images
docker-compose build
Build and start the swarm
docker-compose up -d
Stop the swarm
docker-compose down
List containers in the swarm
docker-compose ps
Remove stopped containers
docker-compose rm
Download: https://robrich.org/slides/welcome-to-docker/docker-ecosystem.pdf