SlideShare a Scribd company logo
Up and Running
With Docker
Presented by Michelle Liu
https://github.com/anonmily/docker-up-and-running
Outline
1. What is Docker?
2. Applications of Docker
3. Terminology: How Docker Works
4. Tools
5. Installation
6. Images
7. Containers
8. Docker Registry
9. Docker Workflow
10. Docker Remote API
11. QA
The Deployment Dilemma
• Inter-dependent dependencies
• Inconsistent environments
• Development != Production
• “Works on my machine…”
The Deployment Dilemma
Lots of dependencies/interactions between services and applications
Different approaches and tools
• Virtualization
• Configuration Management
• Containers
Containerization = standardization
Containerization = Separation of Concerns
Configuration Management
Remember the exact steps needed for
setup and do it all over again for all of
your servers (a recipe)
Docker/Containers
Set up a container/image just once with all
the necessary configuration, then deploy the
same image to all of your servers (a golden
image)
What’s the difference?
Terminology: Images and Containers
Image: A master template for creating Docker
containers, analogous to virtual machine
instances (a “golden image”)
Container: An instance of an image; multiple
containers can be created from a single image.
A container contains isolated processes and
filesystems acting in a similar fashion as virtual
machines; however, a container only includes
the filesystem on top of a shared kernel.
Virtual Machines Containers
What’s the difference? Virtual Machines vs Containers
Virtual Machines
• Kernel not shared between virtual
machines
• Isolated operating systems
• Long-lasting use
• Slower to get running
• Many startup processes
• A single virtual machine image can be
used for multiple virtual machine
clones
Containers
• Kernel of linux host shared between all
containers
• Isolated processes/filesystems
• Ephemeral/long-lasting usage
• Fast to get running
• One startup process
• A single Docker image can be used for
multiple container instances
What’s the difference? Virtual Machines vs Containers
What is Docker used for?
• Ephemeral (temporary) isolated processes (e.g. Codepen, Codeship)
• Short running tasks, maintenance scripts, or worker processes that
receive then process a workload
• Running and deploying stateless applications
• Web frontends and backend APIs
• Running isolated environments with imposed CPU/memory limits
• …and more!
This means that containers are
• More lightweight
• Can be started, stopped, and
restarted more quickly
• Easier to migrate
• Easier to communicate
between containers
What’s the difference? Virtual Machines vs Containers
Docker Server vs Docker Client
Docker server/daemon:
The docker server/daemon runs containers within as
processes, acting as a virtual bridge to the host operating
system (containers are isolated)
Docker client: The command line interface (CLI) that is
able to connect to the Docker server (specified by the
DOCKER_HOST environmental variable) and tell it what to
do. This can run on your local machine or on the same
host as the Docker server.
Docker Server vs CLI
Docker Server vs CLI
Docker Server vs CLI
Docker Server vs CLI
Docker Server vs CLI
WORKSHOP
Install Docker
Installation - Linux
curl -fsSL https://get.docker.com/ | sh
service docker start
Will run a setup script for installing docker
Easy setup
Installation - Linux
apt-get update
apt-get purge lxc-docker*
apt-get purge docker.io*
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys
58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo debian-jessie main" >
/etc/apt/sources.list.d/docker.list
apt-get -y install apt-transport-https
apt-get -y update
apt-get -y install docker-engine
service docker start
Debian/Ubuntu
curl https://raw.githubusercontent.com/anonmily/scripts/master/docker-setup-debian | bash
Or, just
Installation - Linux
yum install docker
service docker start
Fedora
curl https://raw.githubusercontent.com/anonmily/scripts/master/docker-setup-yum | bash
Or, just
Installation – Non-Linux
• Download and install the Docker
Toolbox
https://www.docker.com/docker-
toolbox
• Open the Docker Quickstart
Terminal
WORKSHOP
Docker Server/CLI
Docker Server/CLI
docker-machine create –driver virtualbox host1
docker-machine create –driver virtualbox host2
docker-machine create –driver virtualbox host3
Create a new docker host
docker-machine ls
List docker hosts
Docker Server/CLI
docker-machine stop host1
Stop docker host
docker-machine start host1
Start docker host
docker-machine restart host1
Restart docker host
Docker Server/CLI
docker-machine ip host1
Get IP address of host
docker-machine env host1
Get environmental variables of the host
Docker Server/CLI
eval $(docker-machine-env host1)
Set environmental variables of CLI to communicate with a host
** If you get a “Cannot connect to the Docker daemon. Is the docker daemon running on this host?” error
when attempting to use the Docker CLI, make sure the environmental variables are set for your Docker host
Docker Images
• Docker images are a saved state of the
container. They’re the “golden image” for
your containers, and multiple containers
based off the same mage can be run at
the same time (executing different
commands etc in the same environment if
necessary)
• Image ID = hashed representation of the
image, a unique identifier
• A Dockerfile is a file that describes all the
steps needed to build a Docker image
Docker Images
• Images can be tagged with a name
and a version label (e.g.
nginx:latest, ubuntu:14:04)
• Images are stored in and can be
retrieve from Docker Repositories
• Docker Hub: Public repository with
common base images
• Private Registry: Deploy your own
Docker registry
Storing Docker Images
• Docker registry: A server that hosts your
Docker images; it acts in a fashion
analogous to repositories in that you can
push and pull images from the registry.
You can use a public registry like Docker
hub, or you can setup your own for private
images.
• Docker Hub: A public Docker registry that
is the default for pulling images. It
provides many common base images such
as Debian, Ubuntu, Fedora, etc.
Docker Hub
Deploy your own registry server
WORKSHOP
Docker Images
Docker Images
docker pull nginx:latest
Pull/get an image (from Docker Hub)
# login to DockerHub
docker login
# private registry
docker login https://myownregistry.com:5000
Login to a registry
• Docker will save your login credentials in ~/.docker/config.json
docker images
See your downloaded/available images
Docker Images
docker build –t webapp1:latest .
Build a new image tagged “webapp1:latest” from a Dockerfile
docker run --name="myapp" -p 80:80 -d nginx:latest nginx
-g "daemon off;"
Run a container from an image
• --name=“myapp” Run a new container called “myapp”
• -p 80:80 Expose port 80 of the host and map it to port 80 of the container
• -d Run daemonized
• nginx:latest Base image
• nginx –g “daemon off;” Command to start the container with
Docker Images
docker exec –it nodeapp bash
Execute a command into a container
docker ps # running containers
docker ps –a # all containers
List containers
docker stop nodeapp
Stop container
docker rm nodeapp
Remove container
Docker Images
docker save myimage:latest > myimage.tar
Save an image to a tarball
docker import myimage.tar
Import an image from a tarball
docker commit –m “newconfig” mycontainer myimage:latest
Commit/save the current state of a container to the image
Docker Images
docker rmi myimage:latest
Remove an image
docker rmi $(docker images –q –f “dangling=true”)
Delete all untagged images
docker rmi $(docker images –q -)
Delete all images on Docker host
What is a Dockerfile?
• Instructions for how to build a
Docker image
FROM anonmily/node:latest
MAINTAINER Michelle Liu
<michelle@michelleliu.io>
COPY src/node_modules /src/node_modules
COPY certs /src/certs
EXPOSE 443
WORKDIR /src
ENV PATH /src/bin:$PATH
COPY src/bin /src/bin
COPY src/app /src/app
COPY src/server.js src/app.js
src/package.json Makefile /src/
CMD ["startserver"]
Anatomy of a Dockerfile
• FROM what base image to use for the new image
• MAINTAINER who maintains the image
• COPY source destination copy files from the source location to destination
• ENV set environmental variables
• WORKDIR set working directory of the container
• CMD run command
• EXPOSE indicates what ports should be available for exposure
Dockerizing a Node application
FROM anonmily/node:latest
MAINTAINER Michelle Liu
<michelle@michelleliu.io>
COPY src/node_modules /src/node_modules
COPY certs /src/certs
EXPOSE 443
WORKDIR /src
ENV PATH /src/bin:$PATH
COPY src/bin /src/bin
COPY src/app /src/app
COPY src/server.js src/app.js
src/package.json Makefile /src/
CMD ["startserver"]
/Src
app/
app.js
bin/
startserver
certs
gulpfile.js
node_modules
server.js
Makefile
Bin/
Certs/
Src/
app.js
bin/
startserver
gulpfile.js
node_modules
server.js
Server.js
Production.env
Dockerfile
Makefile
Original Folder Docker Container
Utilizing the Layer Cache
FROM anonmily/node:latest
MAINTAINER Michelle Liu <michelle@michelleliu.io>
COPY src/node_modules /src/node_modules
COPY certs /src/certs
EXPOSE 443
WORKDIR /src
ENV PATH /src/bin:$PATH
COPY src/bin /src/bin
COPY src/app /src/app
COPY src/server.js src/app.js src/package.json
Makefile /src/
CMD ["startserver"]
Least changed
files on top
More
frequently
changed files
on bottom
Building the image
# ./bin/buildapi
docker build -t myregistry.com/nodeapi:latest .
# ./bin/pushapi
docker push myregistry.com/nodeapi:latest
Updating to a newer image
# ./bin/updatecontainer
docker pull myregistry.com/nodeapi:latest
docker kill nodeapicontainer;
docker rm nodeapicontainer;
docker run --name nodeapi01 
-p 443:443 
-dit 
--env-file /home/production.env 
myregistry.com/nodeapi:latest 
startserver
An easy way to deploy
1. Push the new image up onto the Docker registry (e.g. 1.0.0)
2. From the servers, pull down the new image
3. Kill the currently running container based off the old outdated image
4. Run a new container based off the new image
Updating to a newer image
#!/bin/bash
docker build -t myregistry.com/nodeapi:latest .
docker push myregistry.com/nodeapi:latest
ssh -i ~/.ssh/mysshkey root@api.mysite.com 'bash' <
bin/updatecontainer
ssh -i ~/.ssh/mysshkey root@api.mysite2.com 'bash' <
bin/updatecontainer
ssh -i ~/.ssh/mysshkey root@api.mysite3.com 'bash' <
bin/updatecontainer
Startserver
#!/bin/bash
pm2 dump
pm2 start /src/server.js -i 0 --name
nodeapi --no-daemon &
If you want to start your container up with more than
one command, use a bash script
Docker remote API
An API for the Docker daemon/server that allows you to make requests
to/query the server for creating/editing or for information on
containers/images.
Docker remote API
By default, the Docker daemon will run on the unix port at
/var/run/docker.sock. To get started with the Docker remote API, make sure
that you have a cURL version greater than 7.40 so that the –unix-socket
option is available. Then, we can use curl to interact with the remote API by:
curl --unix-socket /var/run/docker.sock http://containers/json
Docker remote API
It’s also possible to bind the Docker daemon to a TCP port at startup by:
docker daemon –H tcp://0.0.0.0:2375 –H /var/run/docker.sock
It will then be possible to access the remote API on the host publicly (though
it is a security issue).
curl http://localhost:2375/containers/json
More resources
• http://view.dckr.info/DockerIntro.pdf
• http://view.dckr.info/DockerAdvanced.pdf
• https://docs.docker.com/engine/articles/dockerfile_best-practices/
• http://blog.thoward37.me/articles/where-are-docker-images-stored/
• http://blog.trifork.com/2013/12/24/docker-from-a-distance-the-remote-api/

More Related Content

PDF
Docker by Example - Basics
PPTX
Docker Introductory workshop
PDF
PDF
containers and virtualization tools ( Docker )
PDF
A Hands-on Introduction to Docker
PDF
Docker by Example - Basics
PDF
Optimizing Docker Images
PDF
Dockerfile
Docker by Example - Basics
Docker Introductory workshop
containers and virtualization tools ( Docker )
A Hands-on Introduction to Docker
Docker by Example - Basics
Optimizing Docker Images
Dockerfile

What's hot (20)

PDF
Docker by Example - Quiz
PDF
Docker
PDF
Docker Introduction
PPTX
Introduction To Docker
PDF
Shipping Applications to Production in Containers with Docker
PDF
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
ODP
Docker - The Linux Container
PPTX
Docker Basics
PPTX
Docker : Container Virtualization
PPTX
Docker Basic Presentation
PDF
Docker for developers
PPTX
Docker, LinuX Container
PPTX
Docker Starter Pack
PDF
Docker puebla bday #4 celebration
PDF
docker installation and basics
PPTX
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
PDF
Docker fundamentals
PPTX
Architecting .NET Applications for Docker and Container Based Deployments
PDF
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
PPTX
Docker and the Container Ecosystem
Docker by Example - Quiz
Docker
Docker Introduction
Introduction To Docker
Shipping Applications to Production in Containers with Docker
What is Docker | Docker Tutorial for Beginners | Docker Container | DevOps To...
Docker - The Linux Container
Docker Basics
Docker : Container Virtualization
Docker Basic Presentation
Docker for developers
Docker, LinuX Container
Docker Starter Pack
Docker puebla bday #4 celebration
docker installation and basics
Docker Tutorial For Beginners | What Is Docker And How It Works? | Docker Tut...
Docker fundamentals
Architecting .NET Applications for Docker and Container Based Deployments
Docker Presentation at the OpenStack Austin Meetup | 2013-09-12
Docker and the Container Ecosystem
Ad

Similar to Up and running with docker (20)

PPTX
Containerization using docker and its applications
PPTX
Containerization using docker and its applications
PDF
Docker up and Running For Web Developers
PDF
Docker Up and Running for Web Developers
PPTX
Powercoders · Docker · Fall 2021.pptx
PDF
Docker From Scratch
PPTX
Dockers and containers basics
PPTX
Getting Started with Docker
PDF
Docker basics
PPTX
Virtualization, Containers, Docker and scalable container management services
PDF
Cloud Native Computing - Part III - Containers
PDF
docker.pdf
PDF
[@NaukriEngineering] Docker 101
PDF
Docker interview Questions-1.pdf
PPTX
Introduction to automated environment management with Docker Containers - for...
PDF
Introduction to Docker, Devops Virtualization and configuration management
PDF
PPTX
docker technology in INTERNET WORLD.pptx
PPSX
Docker and containers - Presentation Slides by Priyadarshini Anand
PDF
Dockercon 23 - Getting started with Docker
Containerization using docker and its applications
Containerization using docker and its applications
Docker up and Running For Web Developers
Docker Up and Running for Web Developers
Powercoders · Docker · Fall 2021.pptx
Docker From Scratch
Dockers and containers basics
Getting Started with Docker
Docker basics
Virtualization, Containers, Docker and scalable container management services
Cloud Native Computing - Part III - Containers
docker.pdf
[@NaukriEngineering] Docker 101
Docker interview Questions-1.pdf
Introduction to automated environment management with Docker Containers - for...
Introduction to Docker, Devops Virtualization and configuration management
docker technology in INTERNET WORLD.pptx
Docker and containers - Presentation Slides by Priyadarshini Anand
Dockercon 23 - Getting started with Docker
Ad

Recently uploaded (20)

PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PDF
Download FL Studio Crack Latest version 2025 ?
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Nekopoi APK 2025 free lastest update
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Transform Your Business with a Software ERP System
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
assetexplorer- product-overview - presentation
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
17 Powerful Integrations Your Next-Gen MLM Software Needs
Download FL Studio Crack Latest version 2025 ?
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
How to Choose the Right IT Partner for Your Business in Malaysia
Nekopoi APK 2025 free lastest update
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Transform Your Business with a Software ERP System
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Salesforce Agentforce AI Implementation.pdf
Operating system designcfffgfgggggggvggggggggg
wealthsignaloriginal-com-DS-text-... (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
assetexplorer- product-overview - presentation
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Why Generative AI is the Future of Content, Code & Creativity?
L1 - Introduction to python Backend.pptx
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx

Up and running with docker

  • 1. Up and Running With Docker Presented by Michelle Liu https://github.com/anonmily/docker-up-and-running
  • 2. Outline 1. What is Docker? 2. Applications of Docker 3. Terminology: How Docker Works 4. Tools 5. Installation 6. Images 7. Containers 8. Docker Registry 9. Docker Workflow 10. Docker Remote API 11. QA
  • 3. The Deployment Dilemma • Inter-dependent dependencies • Inconsistent environments • Development != Production • “Works on my machine…”
  • 5. Lots of dependencies/interactions between services and applications
  • 6. Different approaches and tools • Virtualization • Configuration Management • Containers
  • 9. Configuration Management Remember the exact steps needed for setup and do it all over again for all of your servers (a recipe) Docker/Containers Set up a container/image just once with all the necessary configuration, then deploy the same image to all of your servers (a golden image) What’s the difference?
  • 10. Terminology: Images and Containers Image: A master template for creating Docker containers, analogous to virtual machine instances (a “golden image”) Container: An instance of an image; multiple containers can be created from a single image. A container contains isolated processes and filesystems acting in a similar fashion as virtual machines; however, a container only includes the filesystem on top of a shared kernel.
  • 11. Virtual Machines Containers What’s the difference? Virtual Machines vs Containers
  • 12. Virtual Machines • Kernel not shared between virtual machines • Isolated operating systems • Long-lasting use • Slower to get running • Many startup processes • A single virtual machine image can be used for multiple virtual machine clones Containers • Kernel of linux host shared between all containers • Isolated processes/filesystems • Ephemeral/long-lasting usage • Fast to get running • One startup process • A single Docker image can be used for multiple container instances What’s the difference? Virtual Machines vs Containers
  • 13. What is Docker used for? • Ephemeral (temporary) isolated processes (e.g. Codepen, Codeship) • Short running tasks, maintenance scripts, or worker processes that receive then process a workload • Running and deploying stateless applications • Web frontends and backend APIs • Running isolated environments with imposed CPU/memory limits • …and more!
  • 14. This means that containers are • More lightweight • Can be started, stopped, and restarted more quickly • Easier to migrate • Easier to communicate between containers What’s the difference? Virtual Machines vs Containers
  • 15. Docker Server vs Docker Client Docker server/daemon: The docker server/daemon runs containers within as processes, acting as a virtual bridge to the host operating system (containers are isolated) Docker client: The command line interface (CLI) that is able to connect to the Docker server (specified by the DOCKER_HOST environmental variable) and tell it what to do. This can run on your local machine or on the same host as the Docker server.
  • 22. Installation - Linux curl -fsSL https://get.docker.com/ | sh service docker start Will run a setup script for installing docker Easy setup
  • 23. Installation - Linux apt-get update apt-get purge lxc-docker* apt-get purge docker.io* apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D echo "deb https://apt.dockerproject.org/repo debian-jessie main" > /etc/apt/sources.list.d/docker.list apt-get -y install apt-transport-https apt-get -y update apt-get -y install docker-engine service docker start Debian/Ubuntu curl https://raw.githubusercontent.com/anonmily/scripts/master/docker-setup-debian | bash Or, just
  • 24. Installation - Linux yum install docker service docker start Fedora curl https://raw.githubusercontent.com/anonmily/scripts/master/docker-setup-yum | bash Or, just
  • 25. Installation – Non-Linux • Download and install the Docker Toolbox https://www.docker.com/docker- toolbox • Open the Docker Quickstart Terminal
  • 27. Docker Server/CLI docker-machine create –driver virtualbox host1 docker-machine create –driver virtualbox host2 docker-machine create –driver virtualbox host3 Create a new docker host docker-machine ls List docker hosts
  • 28. Docker Server/CLI docker-machine stop host1 Stop docker host docker-machine start host1 Start docker host docker-machine restart host1 Restart docker host
  • 29. Docker Server/CLI docker-machine ip host1 Get IP address of host docker-machine env host1 Get environmental variables of the host
  • 30. Docker Server/CLI eval $(docker-machine-env host1) Set environmental variables of CLI to communicate with a host ** If you get a “Cannot connect to the Docker daemon. Is the docker daemon running on this host?” error when attempting to use the Docker CLI, make sure the environmental variables are set for your Docker host
  • 31. Docker Images • Docker images are a saved state of the container. They’re the “golden image” for your containers, and multiple containers based off the same mage can be run at the same time (executing different commands etc in the same environment if necessary) • Image ID = hashed representation of the image, a unique identifier • A Dockerfile is a file that describes all the steps needed to build a Docker image
  • 32. Docker Images • Images can be tagged with a name and a version label (e.g. nginx:latest, ubuntu:14:04) • Images are stored in and can be retrieve from Docker Repositories • Docker Hub: Public repository with common base images • Private Registry: Deploy your own Docker registry
  • 33. Storing Docker Images • Docker registry: A server that hosts your Docker images; it acts in a fashion analogous to repositories in that you can push and pull images from the registry. You can use a public registry like Docker hub, or you can setup your own for private images. • Docker Hub: A public Docker registry that is the default for pulling images. It provides many common base images such as Debian, Ubuntu, Fedora, etc.
  • 35. Deploy your own registry server
  • 37. Docker Images docker pull nginx:latest Pull/get an image (from Docker Hub) # login to DockerHub docker login # private registry docker login https://myownregistry.com:5000 Login to a registry • Docker will save your login credentials in ~/.docker/config.json docker images See your downloaded/available images
  • 38. Docker Images docker build –t webapp1:latest . Build a new image tagged “webapp1:latest” from a Dockerfile docker run --name="myapp" -p 80:80 -d nginx:latest nginx -g "daemon off;" Run a container from an image • --name=“myapp” Run a new container called “myapp” • -p 80:80 Expose port 80 of the host and map it to port 80 of the container • -d Run daemonized • nginx:latest Base image • nginx –g “daemon off;” Command to start the container with
  • 39. Docker Images docker exec –it nodeapp bash Execute a command into a container docker ps # running containers docker ps –a # all containers List containers docker stop nodeapp Stop container docker rm nodeapp Remove container
  • 40. Docker Images docker save myimage:latest > myimage.tar Save an image to a tarball docker import myimage.tar Import an image from a tarball docker commit –m “newconfig” mycontainer myimage:latest Commit/save the current state of a container to the image
  • 41. Docker Images docker rmi myimage:latest Remove an image docker rmi $(docker images –q –f “dangling=true”) Delete all untagged images docker rmi $(docker images –q -) Delete all images on Docker host
  • 42. What is a Dockerfile? • Instructions for how to build a Docker image FROM anonmily/node:latest MAINTAINER Michelle Liu <[email protected]> COPY src/node_modules /src/node_modules COPY certs /src/certs EXPOSE 443 WORKDIR /src ENV PATH /src/bin:$PATH COPY src/bin /src/bin COPY src/app /src/app COPY src/server.js src/app.js src/package.json Makefile /src/ CMD ["startserver"]
  • 43. Anatomy of a Dockerfile • FROM what base image to use for the new image • MAINTAINER who maintains the image • COPY source destination copy files from the source location to destination • ENV set environmental variables • WORKDIR set working directory of the container • CMD run command • EXPOSE indicates what ports should be available for exposure
  • 44. Dockerizing a Node application FROM anonmily/node:latest MAINTAINER Michelle Liu <[email protected]> COPY src/node_modules /src/node_modules COPY certs /src/certs EXPOSE 443 WORKDIR /src ENV PATH /src/bin:$PATH COPY src/bin /src/bin COPY src/app /src/app COPY src/server.js src/app.js src/package.json Makefile /src/ CMD ["startserver"] /Src app/ app.js bin/ startserver certs gulpfile.js node_modules server.js Makefile Bin/ Certs/ Src/ app.js bin/ startserver gulpfile.js node_modules server.js Server.js Production.env Dockerfile Makefile Original Folder Docker Container
  • 45. Utilizing the Layer Cache FROM anonmily/node:latest MAINTAINER Michelle Liu <[email protected]> COPY src/node_modules /src/node_modules COPY certs /src/certs EXPOSE 443 WORKDIR /src ENV PATH /src/bin:$PATH COPY src/bin /src/bin COPY src/app /src/app COPY src/server.js src/app.js src/package.json Makefile /src/ CMD ["startserver"] Least changed files on top More frequently changed files on bottom
  • 46. Building the image # ./bin/buildapi docker build -t myregistry.com/nodeapi:latest . # ./bin/pushapi docker push myregistry.com/nodeapi:latest
  • 47. Updating to a newer image # ./bin/updatecontainer docker pull myregistry.com/nodeapi:latest docker kill nodeapicontainer; docker rm nodeapicontainer; docker run --name nodeapi01 -p 443:443 -dit --env-file /home/production.env myregistry.com/nodeapi:latest startserver
  • 48. An easy way to deploy 1. Push the new image up onto the Docker registry (e.g. 1.0.0) 2. From the servers, pull down the new image 3. Kill the currently running container based off the old outdated image 4. Run a new container based off the new image
  • 49. Updating to a newer image #!/bin/bash docker build -t myregistry.com/nodeapi:latest . docker push myregistry.com/nodeapi:latest ssh -i ~/.ssh/mysshkey [email protected] 'bash' < bin/updatecontainer ssh -i ~/.ssh/mysshkey [email protected] 'bash' < bin/updatecontainer ssh -i ~/.ssh/mysshkey [email protected] 'bash' < bin/updatecontainer
  • 50. Startserver #!/bin/bash pm2 dump pm2 start /src/server.js -i 0 --name nodeapi --no-daemon & If you want to start your container up with more than one command, use a bash script
  • 51. Docker remote API An API for the Docker daemon/server that allows you to make requests to/query the server for creating/editing or for information on containers/images.
  • 52. Docker remote API By default, the Docker daemon will run on the unix port at /var/run/docker.sock. To get started with the Docker remote API, make sure that you have a cURL version greater than 7.40 so that the –unix-socket option is available. Then, we can use curl to interact with the remote API by: curl --unix-socket /var/run/docker.sock http://containers/json
  • 53. Docker remote API It’s also possible to bind the Docker daemon to a TCP port at startup by: docker daemon –H tcp://0.0.0.0:2375 –H /var/run/docker.sock It will then be possible to access the remote API on the host publicly (though it is a security issue). curl http://localhost:2375/containers/json
  • 54. More resources • http://view.dckr.info/DockerIntro.pdf • http://view.dckr.info/DockerAdvanced.pdf • https://docs.docker.com/engine/articles/dockerfile_best-practices/ • http://blog.thoward37.me/articles/where-are-docker-images-stored/ • http://blog.trifork.com/2013/12/24/docker-from-a-distance-the-remote-api/