SlideShare uma empresa Scribd logo
1 de 86
Baixar para ler offline
Camping In Containers - Docker For Everyone
Brian Hogan
@bphogan on Twitter
Hi. I'm Brian.
— Programmer (http://github.com/napcs)
— Author (http://bphogan.com/publications)
— Musician (http://soundcloud.com/bphogan)
— Teacher
— Technical Editor @ DigitalOcean
Ask me anything.
Here's where we're going today. We'll talk about containers and images in a general sense,
and we'll talk about Docker itself and how it fits in. Then we'll look at Docker-compose,
docker-machine, and Docker's new Swarm mode. Finally, we'll talk about next steps.
Roadmap
— Containers and Images
— Docker
— docker-compose
— docker-machine
— Docker Swarm Mode
— Where to go next
Disclaimers and Rules
— This is a talk for people new
to Docker.
— This is based on my personal
experience.
— If I go too fast, or I made a
mistake, speak up.
— Ask questions any time.
— If you want to argue, buy me
a beer later.
Containers are a method of operating system virtualization that allow you
to run an application and its dependencies in resource-isolated processes.
Containers
Operating system
virtualization for apps and
dependencies.
Virtual machines virtualize the hardware so you can run multiple operating systems.
Containers share the host OS kernel and, usually, the binaries and libraries, too. Containers are
a lot more light-weight than virtual machines since they can share a lot of the same resources.
Containers vs Virtual Machines
— Containers virtualize the OS
— Virtual machines virtualize the hardware
Docker is an open-source project that automates deployment of apps in containers.
Docker provides a suite of tools for defining container images, creating containers, and
deploying containers to production.
Docker
Automates deployment of apps
in containers
The containeriztion market is getting crowded.
Containers and Docker are not the same thing!
Docker is just one way of implementing and managing
containers. Other tools exist.
— Linux Containers (LXC/LXD)
— rkt
— Other emerging standards
An image is an executable package for your software, including the software you need to run, all of
the configuration files, and all the dependencies. If you have a web app, an image of the app will
contain your code, your configuration, your web server, and even your web server's configuration.
Images
— "Container image" is an
executable package for
so!ware.
— It's an immutable snapshot
of a container.
— A container is a running
instance of an image.
We create new images from existing images. Think of it in layers. You have an Ubuntu
image, but then you need Node. You make a Node image by basing it on the Ubuntu
image. If you have an app, you might base your app's image on the Node image.
Images Build Upon Other Images
ubuntu:16.04
|___node:6
|__your_custom_app
Where do images come from? Other people make them available
through Registries. Docker Hub is the main one for open source software.
Docker Hub
Docker Hub is the most popular registry. The Docker Store is a more enterprise-
friendly place to get "blessed" images. Publish your images for use in deployments
Docker Registries
— Docker Hub (free public
registry, paid private
registry)
— The Docker Store
— Create your own using the
registry image
So why should you care about all of these things? Well, here are a few reasons. First, you'll be able to set up your
development environments quickly. We'll look into how that works. You'll also be able to deploy your infrastructure
faster, and you'll be able to version it. Finally, you'll be able to scale things out a lot more easily, using less resources.
Why should I care???
— Quick development
environment setups
— Deploy production apps and
dependencies in production
— Create versions of your
infrastructure
— Scale out to meet demands
Docker Engine
lightweight and powerful open source containerization
technology combined with a work ïŹ‚ow for building and
containerizing your applications.
Docker for Windows and Docker for Mac provide a tiny virtualization layer. The containers
need a Linux operating system kernel. These installers provide that while hooking into the
native host OS components.
Installing Docker
— Docker for Windows https://www.docker.com/
docker-windows
— Docker for Mac https://www.docker.com/docker-
mac
— OïŹƒcial repos for Linux
— Your cloud provider probably has support
That takes care of the stuff you already know about. We're going to run through
some basics that will show you what's possible, but also look at what not to do!
Basics for Developers
One of the first things you can do with Docker is to use it to run a Linux command in
an isolated environment. This command runs a new container using the ubuntu ,
then executes the uname -a command in the container. In this example, the
ubuntu image wasn't found locally, so Docker downloads it first, then creates the
container and runs the program.
Docker containers stop running when the foreground process exits.
Run a command in a new container
$ docker run ubuntu uname -a
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
c62795f78da9: Downloading [========> ] 7.348 MB/45.56 MB
d4fceeeb758e: Download complete
5c9125a401ae: Download complete
0062f774e994: Download complete
6b33fd031fac: Download complete
Linux a941752d46a9 4.9.13-moby #1 SMP Sat Mar 25 02:48:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
This launches a bash shell in the container and gives us a prompt we can interact
with. The container will stay running until we type exit. The container exits when
the foreground task ends.
Run an interactive command in a new container
$ docker run -i -t ubuntu /bin/bash
— -i keeps STDIN running
— -t attaches local terminal to the session
— ubuntu is the image name
— /bin/bash is the command we're running
To see running containers, we use the docker ps
command. Right now there are no running containers.
List Running Containers
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
We use docker ps --all to show all containers we've created. We have two containers
showing up here, both stopped. Containers hang around even after they've stopped. Unfortunately,
if you don't know that, you'll find yourself with lots of extra containers hanging around.
List all containers
$ docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b503470265c2 ubuntu "/bin/bash" 2 hours ago Exited (127) 34 seconds ago reverent_franklin
23867bd9c77a ubuntu "uname -a" 2 hours ago Exited (0) 53 seconds ago peaceful_goodall
Clean up containers you don't need with the docker rm command. You can
remove containers by their ID or their name. The names are generated by Docker if
you don't specify a name.
Remove containers
Remove by name or by container ID
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b503470265c2 ubuntu "/bin/bash" 2 hours ago Exited (127) 34 seconds ago reverent_franklin
23867bd9c77a ubuntu "uname -a" 2 hours ago Exited (0) 53 seconds ago peaceful_goodall
$ docker rm b503470265c2
$ docker rm peaceful_goodall
By using the --rm switch, we can have the container
removed once the running process stops.
Self-removing Containers
$ docker run --rm -i -t ubuntu bin/bash
-rm removes container when the process stops.
The containers we created previously had names assigned by Docker
Engine. But we can, and should, name them when we create them.
Name Containers
$ docker run -i -t --name bash ubuntu bin/bash
--name lets you specify the name.
You can execute commands in a running container with the docker exec command.
This way you aren't spinning up a new container just to run one command.
Issue Commands to Containers
Run a container in the background (-d)
$ docker run -d -i --name bash ubuntu bin/bash
Execute commands in this container
$ docker exec bash ls
$ docker exec bash uname -a
$ docker exec -i -t bash top
Need to get into the console rather than running stuff? You can do this a couple of ways. First, you can
just run use docker attach. Use the sig-proxy option when you attach, so that you can safely detach
with control c. Otherwise you might accidentally kill off whatever service is running in the container.
Attach to Running Container
Create another shell
docker exec -i -t bash bin/bash
Or attach:
$ docker attach --sig-proxy=false bash
Use the docker start and docker stop commands to shut
down or startup the contaienr again.
Stop and Start Containers
$ docker run -d -i -t --name bash ubuntu bin/bash
$ docker stop bash
...
$ docker start bash
$ docker exec ...
One popular way you can use Docker is to run scripts in a clean environment for testing.
Docker lets you mount a volume, which maps a folder to a folder inside of the container.
Run local stuff in a Container
— Create your ïŹles
— Mount the working directory as a volume
— Launch a container
— Run your stuïŹ€
So let's create a simple Bash script that just prints out a string identifying that
we're running from Docker, but we'll also print out the OS info using uname.
Create your ïŹles
$ touch hello.sh
File contents:
echo "hello from Docker"
uname -a
So we'll create a container that runs in the background and maps the
current working directory to a folder called /myfiles on the serverr.
Build a Container
$ docker run --rm -d -i -t 
-v $PWD:/myfiles 
--name hello ubuntu bin/bash
— -v maps local_folder to destination_folder
Once the container's running, we can use docker exec command to execute
the script on the box. The neat thing is that we can modify this file locally and then
keep running it in the container.
Run your stuff
$ docker exec hello bash /myfiles/hello.sh
hello from Docker
Linux dc90f485eb6f 4.9.36-moby #1 SMP Wed Jul 12 15:29:07 UTC 2017
x86_64 x86_64 x86_64 GNU/Linux
To just run the script in a new container each time, just don't
use the daemonize feature and specify the script directly.
One-liner with no state
docker run --rm -i -t 
-v $PWD:/myfiles 
--name hello ubuntu bin/bash /myfiles/hello.sh
We use a dockerfile to create a custom image. We can install software using the package
manager, we can also copy local files into the image and define the environment
variables, ports, and volumes we want to use.
DockerïŹles
Create custom images
— Install so!ware
— Copy local ïŹles to the image
— Set up ports, volumes, and environment variables
Here's an example of a Dockerfile that sets up vim, curl, git,
and some build tools
A DockerïŹle for Development
# base image
FROM ubuntu:16.04
# update and install software
RUN apt-get -yqq update
RUN apt-get -yqq install vim curl git build-essential
# copy over a local file
ADD vimrc ~/.vimrc
# startup command
CMD ["bin/bash"]
We use the build command to create an image from
the Dockerfile. We also namespace our images.
Create Image from DockerïŹle
$ docker build -t napcs/devenv .
Sending build context to Docker daemon 7.68 kB
Step 1/5 : FROM ubuntu:16.04
---> 6a2f32de169d
Step 2/5 : RUN apt-get -yqq update
...
---> 1a8f00b704b1
Step 3/5 : RUN apt-get -yqq install vim curl git build-essential
...
---> d4e10d49f0c1
Step 4/5 : ADD vimrc /root/.vimrc
...
---> b662a9c211ed
Step 5/5 : CMD bin/bash
...
---> 77970ae0dd60
Successfully built 77970ae0dd60
The docker images command shows you the available images.
The new image we created from the dockerfile is there.
List Available Images
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 16.04 6a2f32de169d 3 months ago 117MB
...
napcs/devenv latest 77970ae0dd60 22 seconds ago 436 MB
Want something more practical? Let's do something similar
with Apache.
Make a testing web server
— Create a DockerïŹle
— Launch the container
— Map the current folder as the webroot
— Map the port
Let's create our own Dockerfile for this. We could just grab an existing image, but this
gives us more experience with Dockerfiles. Once again we base the image off an Ubuntu
base image. Then we install the packages. We expose port 80 from the container.
Create a DockerïŹle
FROM ubuntu:16.04
# packages
RUN apt-get -yqq update;
RUN apt-get -yqq install apache2
# port
EXPOSE 80
# startup command for Apache so it doesn't background
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Build the image
$ docker build -t napcs/apache .
Sending build context to Docker daemon 3.072 kB
Step 1/5 : FROM ubuntu:16.04
---> 6a2f32de169d
Step 2/5 : RUN apt-get -yqq update;
...
---> 6827312d57a3
Step 3/5 : RUN apt-get -yqq install apache2
...
---> 27ff55c5eddb
Step 4/5 : EXPOSE 80
...
---> df2cebb281dc
Step 5/5 : CMD /usr/sbin/apache2ctl -D FOREGROUND
...
---> 2793e761e2cd
Alright. The image is created. We'll create a simple web page, then fire up the
container. We use the -p option to fire up the container and map the local port 8000
to port 80 in the container.
Serve the Current Dir
$ echo "<h1>hello world</h1>" > index.html
$ docker run --rm -d -p 8000:80 
-v $PWD:/var/www/html --name web napcs/apache
-p binds host port to destination port.
We can now access localhost:8000 and see the web page. cURL
can show us the headers, so you can clearly see we're using Apache.
Test with cURL
$ curl -i localhost:8000
HTTP/1.1 200 OK
Date: Sat, 22 Apr 2017 04:16:27 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Wed, 22 Mar 2017 14:12:32 GMT
ETag: "15-54b5259f23400"
Accept-Ranges: bytes
Content-Length: 21
Content-Type: text/html
<h1>hello world</h1>
Storing data in a container is risky because if you lose the
container, you lose the data.
Data Persistence
We'll create a Redis container and map the ports to our
host. Then we'll start up the redis CLI.
Example: Redis Data
Start Redis in a container:
$ docker run -d --name redis 
-p 6379:6379 redis redis-server
Connect with local client:
$ redis-cli
So we save a value into Redis and we exit the cli. Then we
stop and remove the container.
Test Persistence
Save a value:
> set name "TCCC"
> exit
Stop and remove container
$ docker stop redis
$ docker rm redis
So, what happened to the data we just stuck in the
container? What would we be able to do about this?
Where's the data?
We can use an external volume. The redis container stores Redis data in a data
folder in the root folder of the container. Like we did with Apache, we just use a
volume to map that data over.
Use External Volumes for Data
$ mkdir data
$ docker run --rm -d --name redis 
-v $PWD/data:/data 
-p 6379:6379 redis redis-server
If we persist data in Redis now, it's saved outside of the
container.
Review
— What does the --rm option do?
— Why would we use -i -t when running a container?
— What does -p 3000:80 do?
— What's the diïŹ€erence between a container and an
image?
Docker Compose makes it easy to run a multi-container Docker app. Like a web app and
its database. You could run the web app and database in the same container, but you
wouldn't, because you'll want to scale out.
Docker Compose
Tool for running multi-
container Docker apps.
Process
— DeïŹne a DockerïŹle for your app
— DeïŹne the services that make up your app in a
docker-compose ïŹle
— Launch the services.
Our App
— Node.JS and Redis app.
— Every visit to the site increments a counter in a
Redis database.
— Run with forever so it stays running in the container
and restarts if there's a crash.
Code
const express = require('express'),
http = require('http'),
redis = require('redis').createClient('6379', 'redis'),
app = express(),
port = 3000;
app.get('/', function(req, resp, next) {
redis.incr('counter', function(err, counter) {
if (err) return next(err);
resp.send('<h1>This page has been viewed ' + counter + ' times</h1>');
});
});
http.createServer(app).listen(port, function() {
console.log('Demo listening on port ' + port);
});
Dockerize an app
— DeïŹne the environment
— Specify the ïŹles to copy into the image
— Expose ports
— DeïŹne startup commands
Build a dockerfile by using the node version 6 image as our base. We'll then install the forever npm
package, which we can use to run Node apps and restart them if something fails. We then upload the
package json file to a temp folder and install the packages. This way the packages will be cached. Then we
move them into the actual app folder, copy our app up, expose the port, and define the startup command.
DockerïŹle
FROM node:6
RUN npm install -g forever
# Provides cached layer for node_modules
ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /app
RUN cp -a /tmp/node_modules /app/
# Define working directory
WORKDIR /app
ADD index.js /app
# Port
EXPOSE 3000
# Startup command
CMD ["forever", "/app/index.js"]
A Compose file defines the services that make up your stack. We define the app and
the database, and we can define how the volumes work and what ports get exposed.
For the Node app, we tell docker compose to just build the local folder using the
Dockerfile. For Redis, we tell it to use the Redis image. We tell Redis to use a data
volume similar to what we did before. The Port part here is a shorthand notation - if
the host and container port are the same, we can just list a single port.
Compose ïŹle
version: "3"
services:
app:
build: .
ports:
- "3000:3000"
redis:
image: redis
volumes:
- ./data:/data
ports:
- "6379"
Starting the services is easy. We use docker compose up.
Stopping is just as easy.
Starting and Stopping the Services
Start
$ docker compose up
Stop
$ docker compose down
Docker Machine
— Create and manage Docker
environments on virtual
machines
— Create and manage Docker
environments on remote
machines
— Treat a remote Docker
Engine as if it were local
Example: Create machine with VirtualBox
Create machine
$ docker-machine create --driver virtualbox tccc
Creating CA: /Users/brianhogan/.docker/machine/certs/ca.pem
Creating client certificate: /Users/brianhogan/.docker/machine/certs/cert.pem
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!
To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env tccc
Use Docker Client with New Machine
$ docker-machine env tccc
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/brianhogan/.docker/machine/machines/tccc"
export DOCKER_MACHINE_NAME="tccc"
# Run this command to configure your shell:
# eval $(docker-machine env tccc)
$ eval $(docker-machine env tccc)
This is an example of using docker machine to create a machine on DigitalOcean. There
are other drivers you can use to create machines on other cloud providers. There's also a
generic driver you can use if you need to set up machines using your own infrastructure.
Example: Create a remote server on DigitalOcean
$ docker-machine create --driver digitalocean 
--digitalocean-image ubuntu-16-04-x64 
--digitalocean-access-token $DOTOKEN 
tccc
— driver supports cloud providers. Drivers available
for Azure and EC2, as well as others.
— --digitalocean-image speciïŹes the machine image to
use.
— $DOTOKEN is an env variable holding an API token
— tccc is our machine name.
Using the remote machine locally
$ docker-machine env tccc
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://45.55.173.165:2376"
export DOCKER_CERT_PATH="/Users/brianhogan/.docker/machine/machines/tccc"
export DOCKER_MACHINE_NAME="tccc"
# Run this command to configure your shell:
# eval $(docker-machine env tccc)
$ eval $(docker-machine env tccc)
You can tell your local Docker client to use your
remote machine's docker host as if it were running
locally.
Deploy App with Compose
Switch to the remote machine
$ eval $(docker-machine env tccc)
Bring up app:
$ docker-compose up -d
Get the IP
$ docker-machine ip tccc
When you switch your environment with docker-machine, all docker commands
are sent to the remote docker engine. If you want to put things back to point to
your local docker engine, you use the -u option.
Return back to Local Docker Engine
$ docker-machine env -u
unset DOCKER_TLS_VERIFY
unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset DOCKER_MACHINE_NAME
# Run this command to configure your shell:
# eval $(docker-machine env -u)
$ eval $(docker-machine env -u)
Review
— What's the diïŹ€erence between docker-machine and
docker-compose?
— What does docker-machine env do?
— How do you get the IP address of the remote
machine?
Swarm Mode
— Cluster management built in to Docker Engine
— Decentralized design with service discovery and
multi-host networking
— Load balancing and scaling
— Replaces Docker Swarm
Deploying to a Swarm Mode Cluster
— Create the machines with docker-machine
— Create at least one swarm master
— Create at least one worker
— Push your app image to a Docker Registry
— Deploy with docker compose
Let's create three machines for our swarm. One of these will be the swarm "master",
although I like to use the term "swarm boss" instead. The other two will be our workers.
We'll create these on DigitalOcean's cloud..
Create a Swarm
$ docker-machine create --driver digitalocean 
--digitalocean-image ubuntu-16-04-x64 
--digitalocean-access-token $DOTOKEN 
tccc-boss
$ docker-machine create --driver digitalocean 
--digitalocean-image ubuntu-16-04-x64 
--digitalocean-access-token $DOTOKEN 
tccc-worker1
$ docker-machine create --driver digitalocean 
--digitalocean-image ubuntu-16-04-x64 
--digitalocean-access-token $DOTOKEN 
tccc-worker2
First, we create the swarm manager. We have to specify its IP address but we can use
docker-machine ip to do that. When we run this command, it'll give us the command to
run for each worker.
Create a Swarm Manager
$ eval "$(docker-machine env tccc-boss)"
$ docker swarm init --advertise-addr $(docker-machine ip tccc-boss)
Swarm initialized: current node (s4p3vlului2hu8d2beixpu0wa) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join 
--token SWMTKN-1-1e60k6k5jmzirfx4bkb3j1pzdsay9ocq5qix0bl91vnuv3ryp3-7o0g6sly1etsxtj33c1hxnoav 
192.168.99.101:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
To connect each machine, switch your environment to the worker and paste in the
command you were given. The token is unique to your swarm, and also identifies the
machien as a worker. Swarm masters have a different token.
Connect the Workers
$ eval "$(docker-machine env tccc-worker1)"
$ docker swarm join 
--token SWMTKN-1-0opi6iq7zh5brglm01m2beeueql9xt0k1tbfx5u6s519inghxr-8mu5o85bxupzp4ykf4shsiifm 
192.168.99.101:2377
$ eval "$(docker-machine env tccc-worker2)"
$ docker swarm join 
--token SWMTKN-1-0opi6iq7zh5brglm01m2beeueql9xt0k1tbfx5u6s519inghxr-8mu5o85bxupzp4ykf4shsiifm 
192.168.99.101:2377
To see the machines in the swarm, switch back to the swarm manager.
Then use docker node ls. You'll see which one is the swarm manager.
See The Swarm
$ eval "$(docker-machine env tccc-worker2)"
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
ofqi7n5u52efec1mjrjxikgxd tccc-worker2 Ready Active
s4p3vlului2hu8d2beixpu0wa * tccc-boss Ready Active Leader
sc0exb43oafmr307z71bway1s tccc-worker1 Ready Active
Swarm mode doesn't allow the build option. We have to specify an image. We
don't want to push our image up to a public registry, so we'll just create a registry
on our swarm and we'll push it there.
Docker Hub is great for public things, but you may not want your app pushed up
there because of the cost. So you can create a private registry and push your
image there.
Change Compose File
version: '3'
services:
app:
++ image: 127.0.0.1:5000/noderedis
build: .
ports:
- "3000:3000"
redis:
image: redis
volumes:
- ./data:/data
ports:
- "6379"
Let's test out the app. This will also build the image. You'll see a warning that says it can't
deploy to the entire swarm, but that's ok. We're just making sure things build and start.
Build with Compose to Test Image
$ docker-compose up
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
To deploy your application across the swarm, use `docker stack deploy`.
Creating network "06swarm_default" with the default driver
Building app
Step 1/10 : FROM node:6
6: Pulling from library/node
...
Creating 06swarm_app_1
Creating 06swarm_redis_1
There's an official registry image we can use, so we'll use this command to fire up
a registry service on our swrm. Then we'll use Compose to push the image up.
Create Private Registry
$ docker service create --name registry --publish 5000:5000 registry:2
$ docker-compose push
Finally, we deploy the stack to the swarm using the
compose file.
Deploy
$ docker stack deploy 
--compose-file docker-compose.yml 
noderedis
Ignoring unsupported options: build
Creating network noderedis_default
Creating service noderedis_redis
Creating service noderedis_app
We can see all of the services running on our swarm with the docker service
list command. Our redis server and node app are listed, along with our registry.
Review the Nodes
$ docker service list
ID NAME MODE REPLICAS IMAGE
mhnl5pnm5spd noderedis_redis replicated 1/1 redis:latest
v9iu32g5eqj1 noderedis_app replicated 1/1 127.0.0.1:5000/noderedis:latest
w4x9fep7m5c8 registry replicated 1/1 registry:2
To see just the services in the stack we deployed, use
the docker stack services command.
Explore the stack
$ docker stack services noderedis
ID NAME MODE REPLICAS IMAGE
mhnl5pnm5spd noderedis_redis replicated 1/1 redis:latest
v9iu32g5eqj1 noderedis_app replicated 1/1 127.0.0.1:5000/noderedis:latest
You can access the swarm using the ip address of the
manager or any worker. The mesh network ensures it all works.
Access the app
$ curl http://<ip_address_of_manager>
$ curl http://<ip_address_of_any_worker>
Using the docker service ps command you can
see what node a service runs on.
See where service runs
$ docker service ps noderedis_app
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
7rttqwob67qm noderedis_app.1 127.0.0.1:5000/noderedis:latest tccc-worker1 Running Running 10 minutes ago
You may want to scale out your app to meet the demand. You can do that
with the docker service scale command.
^ You scale up the numbrer of containers we use for our app. I have three
machines, and I can scale this app up to three, but that isn't a limitation. I can
scale the number of containers to a much higher number than machines.
Scale out the app
$ docker service scale noderedis_app=3
noderedis_app scaled to 3
With the app scaled out, look again at the processes. You
can see what nodes each service is running on.
Review the Nodes
$ docker service ps noderedis_app
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
7rttqwob67qm noderedis_app.1 127.0.0.1:5000/noderedis:latest tccc-worker1 Running Running 12 minutes ago
q2pjqf0z8o2w noderedis_app.2 127.0.0.1:5000/noderedis:latest tccc-boss Running Running 6 seconds ago
5oi656f6a0w5 noderedis_app.3 127.0.0.1:5000/noderedis:latest tccc-worker2 Running Running 7 seconds ago
All done? Tear it all down by removing the stack.
Tear it Down
$ docker stack rm noderedis
Review
— How do you add workers to a swarm?
— Can you use docker-compose to push an app to a
swarm?
— What must you do with your app image in order to
deploy with docker-compose?
Container Orchestration
— Scheduling
— (placement, replication / scaling, resurrection,
rescheduling, upgrades, downgrades)
— Resource management (memory, CPU, volumes,
ports, IPs, images)
— Service management (i.e. orchestrating several
containers together using labels, groups,
namespaces, load balancing, readiness checking
Some options
— Rancher
— Kubernetes
Rancher
Easily deploy and run containers in production on any
infrastructure with the most complete container management
platform.
Kubernetes
Open-source system for automating deployment, scaling, and
management of containerized applications.
Next Steps
— These slides (http://bphogan.com/presentations/
docker2017)
— DigitalOcean Docker Tutorials (https://
www.digitalocean.com/community/tags/docker?
type=tutorials)
Questions?
Docker

Mais conteĂșdo relacionado

Mais procurados

Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Alessandro Mignogna
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Binary Studio
 
Vagrant and docker
Vagrant and dockerVagrant and docker
Vagrant and dockerDuckDuckGo
 
Streamline your development environment with docker
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with dockerGiacomo Bagnoli
 
Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Sim Janghoon
 
Docker
DockerDocker
DockerChen Chun
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter PackSaeed Hajizade
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...JĂ©rĂŽme Petazzoni
 
Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Toby Griffiths
 
Hands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbiesHands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbiesYigal Elefant
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demoSandeep Karnawat
 
Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°
Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°
Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°raccoony
 
Docker Online Meetup #3: Docker in Production
Docker Online Meetup #3: Docker in ProductionDocker Online Meetup #3: Docker in Production
Docker Online Meetup #3: Docker in ProductionDocker, Inc.
 
JDO 2019: Tips and Tricks from Docker Captain - Ɓukasz Lach
JDO 2019: Tips and Tricks from Docker Captain - Ɓukasz LachJDO 2019: Tips and Tricks from Docker Captain - Ɓukasz Lach
JDO 2019: Tips and Tricks from Docker Captain - Ɓukasz LachPROIDEA
 
Putting some "logic" in LVM.
Putting some "logic" in LVM.Putting some "logic" in LVM.
Putting some "logic" in LVM.Workhorse Computing
 
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05dotCloud
 
Docker and Puppet — Puppet Camp L.A. — SCALE12X
Docker and Puppet — Puppet Camp L.A. — SCALE12XDocker and Puppet — Puppet Camp L.A. — SCALE12X
Docker and Puppet — Puppet Camp L.A. — SCALE12XJĂ©rĂŽme Petazzoni
 

Mais procurados (18)

Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021Primi passi con Docker - ItalianCoders - 12-01-2021
Primi passi con Docker - ItalianCoders - 12-01-2021
 
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 2
 
Vagrant and docker
Vagrant and dockerVagrant and docker
Vagrant and docker
 
Streamline your development environment with docker
Streamline your development environment with dockerStreamline your development environment with docker
Streamline your development environment with docker
 
Docker - container and lightweight virtualization
Docker - container and lightweight virtualization Docker - container and lightweight virtualization
Docker - container and lightweight virtualization
 
Docker
DockerDocker
Docker
 
Docker Starter Pack
Docker Starter PackDocker Starter Pack
Docker Starter Pack
 
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
 
Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)Docker - from development to production (PHPNW 2017-09-05)
Docker - from development to production (PHPNW 2017-09-05)
 
Hands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbiesHands on introduction to docker security for docker newbies
Hands on introduction to docker security for docker newbies
 
Tech talk on docker with demo
Tech talk on docker with demoTech talk on docker with demo
Tech talk on docker with demo
 
Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°
Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°
Django로 만든 ì›č ì• í”ŒëŠŹìŒ€ìŽì…˜ 도컀띌읎징하Ʞ + 도컀 ì»ŽíŹìŠˆëĄœ 개발 환êČœ ê”Źì¶•í•˜êž°
 
Docker Online Meetup #3: Docker in Production
Docker Online Meetup #3: Docker in ProductionDocker Online Meetup #3: Docker in Production
Docker Online Meetup #3: Docker in Production
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
JDO 2019: Tips and Tricks from Docker Captain - Ɓukasz Lach
JDO 2019: Tips and Tricks from Docker Captain - Ɓukasz LachJDO 2019: Tips and Tricks from Docker Captain - Ɓukasz Lach
JDO 2019: Tips and Tricks from Docker Captain - Ɓukasz Lach
 
Putting some "logic" in LVM.
Putting some "logic" in LVM.Putting some "logic" in LVM.
Putting some "logic" in LVM.
 
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
Dockerfile Basics | Docker workshop #2 at twitter, 2013-11-05
 
Docker and Puppet — Puppet Camp L.A. — SCALE12X
Docker and Puppet — Puppet Camp L.A. — SCALE12XDocker and Puppet — Puppet Camp L.A. — SCALE12X
Docker and Puppet — Puppet Camp L.A. — SCALE12X
 

Semelhante a Docker

Docker - A Ruby Introduction
Docker - A Ruby IntroductionDocker - A Ruby Introduction
Docker - A Ruby IntroductionTyler Johnston
 
ExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and JenkinsExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and JenkinsElasTest Project
 
Docker for mere mortals
Docker for mere mortalsDocker for mere mortals
Docker for mere mortalsHenryk Konsek
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 applicationRoman Rodomansky
 
Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Will Hall
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandPRIYADARSHINI ANAND
 
Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerGuido Schmutz
 
Using Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsUsing Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsMicael Gallego
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014Carlo Bonamico
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...Codemotion
 
Docker 101
Docker 101Docker 101
Docker 101schmidtbt
 
Docker Ecosystem on Azure
Docker Ecosystem on AzureDocker Ecosystem on Azure
Docker Ecosystem on AzurePatrick Chanezon
 
Introduction to Docker - Learning containerization XP conference 2016
Introduction to Docker - Learning containerization  XP conference 2016Introduction to Docker - Learning containerization  XP conference 2016
Introduction to Docker - Learning containerization XP conference 2016XP Conference India
 
Docker navjot kaur
Docker navjot kaurDocker navjot kaur
Docker navjot kaurNavjot Kaur
 
Introduction to Codespaces
Introduction to CodespacesIntroduction to Codespaces
Introduction to CodespacesDinaEsmaeili
 
Using Docker with OpenStack - Hands On!
 Using Docker with OpenStack - Hands On! Using Docker with OpenStack - Hands On!
Using Docker with OpenStack - Hands On!Adrian Otto
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics Ganesh Samarthyam
 
Introduction To Docker
Introduction To DockerIntroduction To Docker
Introduction To DockerHamilton Turner
 

Semelhante a Docker (20)

Docker - A Ruby Introduction
Docker - A Ruby IntroductionDocker - A Ruby Introduction
Docker - A Ruby Introduction
 
ExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and JenkinsExpoQA 2017 Using docker to build and test in your laptop and Jenkins
ExpoQA 2017 Using docker to build and test in your laptop and Jenkins
 
Docker for mere mortals
Docker for mere mortalsDocker for mere mortals
Docker for mere mortals
 
Dockerizing a Symfony2 application
Dockerizing a Symfony2 applicationDockerizing a Symfony2 application
Dockerizing a Symfony2 application
 
Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers Docker Command Line, Using and Choosing containers
Docker Command Line, Using and Choosing containers
 
Docker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini AnandDocker and containers - Presentation Slides by Priyadarshini Anand
Docker and containers - Presentation Slides by Priyadarshini Anand
 
Running the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker ContainerRunning the Oracle SOA Suite Environment in a Docker Container
Running the Oracle SOA Suite Environment in a Docker Container
 
Docker 2014
Docker 2014Docker 2014
Docker 2014
 
Using Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and JenkinsUsing Docker to build and test in your laptop and Jenkins
Using Docker to build and test in your laptop and Jenkins
 
codemotion-docker-2014
codemotion-docker-2014codemotion-docker-2014
codemotion-docker-2014
 
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...Why everyone is excited about Docker (and you should too...) -  Carlo Bonamic...
Why everyone is excited about Docker (and you should too...) - Carlo Bonamic...
 
Docker 101
Docker 101Docker 101
Docker 101
 
Docker Ecosystem on Azure
Docker Ecosystem on AzureDocker Ecosystem on Azure
Docker Ecosystem on Azure
 
Introduction to Docker - Learning containerization XP conference 2016
Introduction to Docker - Learning containerization  XP conference 2016Introduction to Docker - Learning containerization  XP conference 2016
Introduction to Docker - Learning containerization XP conference 2016
 
Docker navjot kaur
Docker navjot kaurDocker navjot kaur
Docker navjot kaur
 
Introduction to Codespaces
Introduction to CodespacesIntroduction to Codespaces
Introduction to Codespaces
 
Using Docker with OpenStack - Hands On!
 Using Docker with OpenStack - Hands On! Using Docker with OpenStack - Hands On!
Using Docker with OpenStack - Hands On!
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Introduction To Docker
Introduction To DockerIntroduction To Docker
Introduction To Docker
 
Docker
DockerDocker
Docker
 

Mais de Brian Hogan

Creating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoCreating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoBrian Hogan
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleBrian Hogan
 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantBrian Hogan
 
Getting Started Contributing To Open Source
Getting Started Contributing To Open SourceGetting Started Contributing To Open Source
Getting Started Contributing To Open SourceBrian Hogan
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With ElmBrian Hogan
 
Testing Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptTesting Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptBrian Hogan
 
FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.Brian Hogan
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignBrian Hogan
 
Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassBrian Hogan
 
Building A Gem From Scratch
Building A Gem From ScratchBuilding A Gem From Scratch
Building A Gem From ScratchBrian Hogan
 
Intro To Advanced Ruby
Intro To Advanced RubyIntro To Advanced Ruby
Intro To Advanced RubyBrian Hogan
 
Turning Passion Into Words
Turning Passion Into WordsTurning Passion Into Words
Turning Passion Into WordsBrian Hogan
 
HTML5 and CSS3 Today
HTML5 and CSS3 TodayHTML5 and CSS3 Today
HTML5 and CSS3 TodayBrian Hogan
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexWeb Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexBrian Hogan
 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryBrian Hogan
 
Intro to Ruby
Intro to RubyIntro to Ruby
Intro to RubyBrian Hogan
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Brian Hogan
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with ShoesBrian Hogan
 
The Why Of Ruby
The Why Of RubyThe Why Of Ruby
The Why Of RubyBrian Hogan
 
Story-driven Testing
Story-driven TestingStory-driven Testing
Story-driven TestingBrian Hogan
 

Mais de Brian Hogan (20)

Creating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with HugoCreating and Deploying Static Sites with Hugo
Creating and Deploying Static Sites with Hugo
 
Automating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and AnsibleAutomating the Cloud with Terraform, and Ansible
Automating the Cloud with Terraform, and Ansible
 
Create Development and Production Environments with Vagrant
Create Development and Production Environments with VagrantCreate Development and Production Environments with Vagrant
Create Development and Production Environments with Vagrant
 
Getting Started Contributing To Open Source
Getting Started Contributing To Open SourceGetting Started Contributing To Open Source
Getting Started Contributing To Open Source
 
Rethink Frontend Development With Elm
Rethink Frontend Development With ElmRethink Frontend Development With Elm
Rethink Frontend Development With Elm
 
Testing Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScriptTesting Client-side Code with Jasmine and CoffeeScript
Testing Client-side Code with Jasmine and CoffeeScript
 
FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.FUD-Free Accessibility for Web Developers - Also, Cake.
FUD-Free Accessibility for Web Developers - Also, Cake.
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and Sass
 
Building A Gem From Scratch
Building A Gem From ScratchBuilding A Gem From Scratch
Building A Gem From Scratch
 
Intro To Advanced Ruby
Intro To Advanced RubyIntro To Advanced Ruby
Intro To Advanced Ruby
 
Turning Passion Into Words
Turning Passion Into WordsTurning Passion Into Words
Turning Passion Into Words
 
HTML5 and CSS3 Today
HTML5 and CSS3 TodayHTML5 and CSS3 Today
HTML5 and CSS3 Today
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To ComplexWeb Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To Complex
 
Stop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard LibraryStop Reinventing The Wheel - The Ruby Standard Library
Stop Reinventing The Wheel - The Ruby Standard Library
 
Intro to Ruby
Intro to RubyIntro to Ruby
Intro to Ruby
 
Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7Intro to Ruby - Twin Cities Code Camp 7
Intro to Ruby - Twin Cities Code Camp 7
 
Make GUI Apps with Shoes
Make GUI Apps with ShoesMake GUI Apps with Shoes
Make GUI Apps with Shoes
 
The Why Of Ruby
The Why Of RubyThe Why Of Ruby
The Why Of Ruby
 
Story-driven Testing
Story-driven TestingStory-driven Testing
Story-driven Testing
 

Último

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžDelhi Call girls
 
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂
CALL ON ➄8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïžcall girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
call girls in Vaishali (Ghaziabad) 🔝 >àŒ’8448380779 🔝 genuine Escort Service đŸ”âœ”ïžâœ”ïž
 
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➄8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Docker

  • 1. Camping In Containers - Docker For Everyone Brian Hogan @bphogan on Twitter
  • 2. Hi. I'm Brian. — Programmer (http://github.com/napcs) — Author (http://bphogan.com/publications) — Musician (http://soundcloud.com/bphogan) — Teacher — Technical Editor @ DigitalOcean Ask me anything.
  • 3. Here's where we're going today. We'll talk about containers and images in a general sense, and we'll talk about Docker itself and how it fits in. Then we'll look at Docker-compose, docker-machine, and Docker's new Swarm mode. Finally, we'll talk about next steps. Roadmap — Containers and Images — Docker — docker-compose — docker-machine — Docker Swarm Mode — Where to go next
  • 4. Disclaimers and Rules — This is a talk for people new to Docker. — This is based on my personal experience. — If I go too fast, or I made a mistake, speak up. — Ask questions any time. — If you want to argue, buy me a beer later.
  • 5. Containers are a method of operating system virtualization that allow you to run an application and its dependencies in resource-isolated processes. Containers Operating system virtualization for apps and dependencies.
  • 6. Virtual machines virtualize the hardware so you can run multiple operating systems. Containers share the host OS kernel and, usually, the binaries and libraries, too. Containers are a lot more light-weight than virtual machines since they can share a lot of the same resources. Containers vs Virtual Machines — Containers virtualize the OS — Virtual machines virtualize the hardware
  • 7. Docker is an open-source project that automates deployment of apps in containers. Docker provides a suite of tools for defining container images, creating containers, and deploying containers to production. Docker Automates deployment of apps in containers
  • 8. The containeriztion market is getting crowded. Containers and Docker are not the same thing! Docker is just one way of implementing and managing containers. Other tools exist. — Linux Containers (LXC/LXD) — rkt — Other emerging standards
  • 9. An image is an executable package for your software, including the software you need to run, all of the configuration files, and all the dependencies. If you have a web app, an image of the app will contain your code, your configuration, your web server, and even your web server's configuration. Images — "Container image" is an executable package for so!ware. — It's an immutable snapshot of a container. — A container is a running instance of an image.
  • 10. We create new images from existing images. Think of it in layers. You have an Ubuntu image, but then you need Node. You make a Node image by basing it on the Ubuntu image. If you have an app, you might base your app's image on the Node image. Images Build Upon Other Images ubuntu:16.04 |___node:6 |__your_custom_app
  • 11. Where do images come from? Other people make them available through Registries. Docker Hub is the main one for open source software. Docker Hub
  • 12. Docker Hub is the most popular registry. The Docker Store is a more enterprise- friendly place to get "blessed" images. Publish your images for use in deployments Docker Registries — Docker Hub (free public registry, paid private registry) — The Docker Store — Create your own using the registry image
  • 13. So why should you care about all of these things? Well, here are a few reasons. First, you'll be able to set up your development environments quickly. We'll look into how that works. You'll also be able to deploy your infrastructure faster, and you'll be able to version it. Finally, you'll be able to scale things out a lot more easily, using less resources. Why should I care??? — Quick development environment setups — Deploy production apps and dependencies in production — Create versions of your infrastructure — Scale out to meet demands
  • 14. Docker Engine lightweight and powerful open source containerization technology combined with a work ïŹ‚ow for building and containerizing your applications.
  • 15. Docker for Windows and Docker for Mac provide a tiny virtualization layer. The containers need a Linux operating system kernel. These installers provide that while hooking into the native host OS components. Installing Docker — Docker for Windows https://www.docker.com/ docker-windows — Docker for Mac https://www.docker.com/docker- mac — OïŹƒcial repos for Linux — Your cloud provider probably has support
  • 16. That takes care of the stuff you already know about. We're going to run through some basics that will show you what's possible, but also look at what not to do! Basics for Developers
  • 17. One of the first things you can do with Docker is to use it to run a Linux command in an isolated environment. This command runs a new container using the ubuntu , then executes the uname -a command in the container. In this example, the ubuntu image wasn't found locally, so Docker downloads it first, then creates the container and runs the program. Docker containers stop running when the foreground process exits. Run a command in a new container $ docker run ubuntu uname -a Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu c62795f78da9: Downloading [========> ] 7.348 MB/45.56 MB d4fceeeb758e: Download complete 5c9125a401ae: Download complete 0062f774e994: Download complete 6b33fd031fac: Download complete Linux a941752d46a9 4.9.13-moby #1 SMP Sat Mar 25 02:48:44 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • 18. This launches a bash shell in the container and gives us a prompt we can interact with. The container will stay running until we type exit. The container exits when the foreground task ends. Run an interactive command in a new container $ docker run -i -t ubuntu /bin/bash — -i keeps STDIN running — -t attaches local terminal to the session — ubuntu is the image name — /bin/bash is the command we're running
  • 19. To see running containers, we use the docker ps command. Right now there are no running containers. List Running Containers $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  • 20. We use docker ps --all to show all containers we've created. We have two containers showing up here, both stopped. Containers hang around even after they've stopped. Unfortunately, if you don't know that, you'll find yourself with lots of extra containers hanging around. List all containers $ docker ps --all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b503470265c2 ubuntu "/bin/bash" 2 hours ago Exited (127) 34 seconds ago reverent_franklin 23867bd9c77a ubuntu "uname -a" 2 hours ago Exited (0) 53 seconds ago peaceful_goodall
  • 21. Clean up containers you don't need with the docker rm command. You can remove containers by their ID or their name. The names are generated by Docker if you don't specify a name. Remove containers Remove by name or by container ID CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b503470265c2 ubuntu "/bin/bash" 2 hours ago Exited (127) 34 seconds ago reverent_franklin 23867bd9c77a ubuntu "uname -a" 2 hours ago Exited (0) 53 seconds ago peaceful_goodall $ docker rm b503470265c2 $ docker rm peaceful_goodall
  • 22. By using the --rm switch, we can have the container removed once the running process stops. Self-removing Containers $ docker run --rm -i -t ubuntu bin/bash -rm removes container when the process stops.
  • 23. The containers we created previously had names assigned by Docker Engine. But we can, and should, name them when we create them. Name Containers $ docker run -i -t --name bash ubuntu bin/bash --name lets you specify the name.
  • 24. You can execute commands in a running container with the docker exec command. This way you aren't spinning up a new container just to run one command. Issue Commands to Containers Run a container in the background (-d) $ docker run -d -i --name bash ubuntu bin/bash Execute commands in this container $ docker exec bash ls $ docker exec bash uname -a $ docker exec -i -t bash top
  • 25. Need to get into the console rather than running stuff? You can do this a couple of ways. First, you can just run use docker attach. Use the sig-proxy option when you attach, so that you can safely detach with control c. Otherwise you might accidentally kill off whatever service is running in the container. Attach to Running Container Create another shell docker exec -i -t bash bin/bash Or attach: $ docker attach --sig-proxy=false bash
  • 26. Use the docker start and docker stop commands to shut down or startup the contaienr again. Stop and Start Containers $ docker run -d -i -t --name bash ubuntu bin/bash $ docker stop bash ... $ docker start bash $ docker exec ...
  • 27. One popular way you can use Docker is to run scripts in a clean environment for testing. Docker lets you mount a volume, which maps a folder to a folder inside of the container. Run local stuff in a Container — Create your ïŹles — Mount the working directory as a volume — Launch a container — Run your stuïŹ€
  • 28. So let's create a simple Bash script that just prints out a string identifying that we're running from Docker, but we'll also print out the OS info using uname. Create your ïŹles $ touch hello.sh File contents: echo "hello from Docker" uname -a
  • 29. So we'll create a container that runs in the background and maps the current working directory to a folder called /myfiles on the serverr. Build a Container $ docker run --rm -d -i -t -v $PWD:/myfiles --name hello ubuntu bin/bash — -v maps local_folder to destination_folder
  • 30. Once the container's running, we can use docker exec command to execute the script on the box. The neat thing is that we can modify this file locally and then keep running it in the container. Run your stuff $ docker exec hello bash /myfiles/hello.sh hello from Docker Linux dc90f485eb6f 4.9.36-moby #1 SMP Wed Jul 12 15:29:07 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  • 31. To just run the script in a new container each time, just don't use the daemonize feature and specify the script directly. One-liner with no state docker run --rm -i -t -v $PWD:/myfiles --name hello ubuntu bin/bash /myfiles/hello.sh
  • 32. We use a dockerfile to create a custom image. We can install software using the package manager, we can also copy local files into the image and define the environment variables, ports, and volumes we want to use. DockerïŹles Create custom images — Install so!ware — Copy local ïŹles to the image — Set up ports, volumes, and environment variables
  • 33. Here's an example of a Dockerfile that sets up vim, curl, git, and some build tools A DockerïŹle for Development # base image FROM ubuntu:16.04 # update and install software RUN apt-get -yqq update RUN apt-get -yqq install vim curl git build-essential # copy over a local file ADD vimrc ~/.vimrc # startup command CMD ["bin/bash"]
  • 34. We use the build command to create an image from the Dockerfile. We also namespace our images. Create Image from DockerïŹle $ docker build -t napcs/devenv . Sending build context to Docker daemon 7.68 kB Step 1/5 : FROM ubuntu:16.04 ---> 6a2f32de169d Step 2/5 : RUN apt-get -yqq update ... ---> 1a8f00b704b1 Step 3/5 : RUN apt-get -yqq install vim curl git build-essential ... ---> d4e10d49f0c1 Step 4/5 : ADD vimrc /root/.vimrc ... ---> b662a9c211ed Step 5/5 : CMD bin/bash ... ---> 77970ae0dd60 Successfully built 77970ae0dd60
  • 35. The docker images command shows you the available images. The new image we created from the dockerfile is there. List Available Images $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu 16.04 6a2f32de169d 3 months ago 117MB ... napcs/devenv latest 77970ae0dd60 22 seconds ago 436 MB
  • 36. Want something more practical? Let's do something similar with Apache. Make a testing web server — Create a DockerïŹle — Launch the container — Map the current folder as the webroot — Map the port
  • 37. Let's create our own Dockerfile for this. We could just grab an existing image, but this gives us more experience with Dockerfiles. Once again we base the image off an Ubuntu base image. Then we install the packages. We expose port 80 from the container. Create a DockerïŹle FROM ubuntu:16.04 # packages RUN apt-get -yqq update; RUN apt-get -yqq install apache2 # port EXPOSE 80 # startup command for Apache so it doesn't background CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
  • 38. Build the image $ docker build -t napcs/apache . Sending build context to Docker daemon 3.072 kB Step 1/5 : FROM ubuntu:16.04 ---> 6a2f32de169d Step 2/5 : RUN apt-get -yqq update; ... ---> 6827312d57a3 Step 3/5 : RUN apt-get -yqq install apache2 ... ---> 27ff55c5eddb Step 4/5 : EXPOSE 80 ... ---> df2cebb281dc Step 5/5 : CMD /usr/sbin/apache2ctl -D FOREGROUND ... ---> 2793e761e2cd
  • 39. Alright. The image is created. We'll create a simple web page, then fire up the container. We use the -p option to fire up the container and map the local port 8000 to port 80 in the container. Serve the Current Dir $ echo "<h1>hello world</h1>" > index.html $ docker run --rm -d -p 8000:80 -v $PWD:/var/www/html --name web napcs/apache -p binds host port to destination port.
  • 40. We can now access localhost:8000 and see the web page. cURL can show us the headers, so you can clearly see we're using Apache. Test with cURL $ curl -i localhost:8000 HTTP/1.1 200 OK Date: Sat, 22 Apr 2017 04:16:27 GMT Server: Apache/2.4.18 (Ubuntu) Last-Modified: Wed, 22 Mar 2017 14:12:32 GMT ETag: "15-54b5259f23400" Accept-Ranges: bytes Content-Length: 21 Content-Type: text/html <h1>hello world</h1>
  • 41. Storing data in a container is risky because if you lose the container, you lose the data. Data Persistence
  • 42. We'll create a Redis container and map the ports to our host. Then we'll start up the redis CLI. Example: Redis Data Start Redis in a container: $ docker run -d --name redis -p 6379:6379 redis redis-server Connect with local client: $ redis-cli
  • 43. So we save a value into Redis and we exit the cli. Then we stop and remove the container. Test Persistence Save a value: > set name "TCCC" > exit Stop and remove container $ docker stop redis $ docker rm redis
  • 44. So, what happened to the data we just stuck in the container? What would we be able to do about this? Where's the data?
  • 45. We can use an external volume. The redis container stores Redis data in a data folder in the root folder of the container. Like we did with Apache, we just use a volume to map that data over. Use External Volumes for Data $ mkdir data $ docker run --rm -d --name redis -v $PWD/data:/data -p 6379:6379 redis redis-server If we persist data in Redis now, it's saved outside of the container.
  • 46. Review — What does the --rm option do? — Why would we use -i -t when running a container? — What does -p 3000:80 do? — What's the diïŹ€erence between a container and an image?
  • 47. Docker Compose makes it easy to run a multi-container Docker app. Like a web app and its database. You could run the web app and database in the same container, but you wouldn't, because you'll want to scale out. Docker Compose Tool for running multi- container Docker apps.
  • 48. Process — DeïŹne a DockerïŹle for your app — DeïŹne the services that make up your app in a docker-compose ïŹle — Launch the services.
  • 49. Our App — Node.JS and Redis app. — Every visit to the site increments a counter in a Redis database. — Run with forever so it stays running in the container and restarts if there's a crash.
  • 50. Code const express = require('express'), http = require('http'), redis = require('redis').createClient('6379', 'redis'), app = express(), port = 3000; app.get('/', function(req, resp, next) { redis.incr('counter', function(err, counter) { if (err) return next(err); resp.send('<h1>This page has been viewed ' + counter + ' times</h1>'); }); }); http.createServer(app).listen(port, function() { console.log('Demo listening on port ' + port); });
  • 51. Dockerize an app — DeïŹne the environment — Specify the ïŹles to copy into the image — Expose ports — DeïŹne startup commands
  • 52. Build a dockerfile by using the node version 6 image as our base. We'll then install the forever npm package, which we can use to run Node apps and restart them if something fails. We then upload the package json file to a temp folder and install the packages. This way the packages will be cached. Then we move them into the actual app folder, copy our app up, expose the port, and define the startup command. DockerïŹle FROM node:6 RUN npm install -g forever # Provides cached layer for node_modules ADD package.json /tmp/package.json RUN cd /tmp && npm install RUN mkdir -p /app RUN cp -a /tmp/node_modules /app/ # Define working directory WORKDIR /app ADD index.js /app # Port EXPOSE 3000 # Startup command CMD ["forever", "/app/index.js"]
  • 53. A Compose file defines the services that make up your stack. We define the app and the database, and we can define how the volumes work and what ports get exposed. For the Node app, we tell docker compose to just build the local folder using the Dockerfile. For Redis, we tell it to use the Redis image. We tell Redis to use a data volume similar to what we did before. The Port part here is a shorthand notation - if the host and container port are the same, we can just list a single port. Compose ïŹle version: "3" services: app: build: . ports: - "3000:3000" redis: image: redis volumes: - ./data:/data ports: - "6379"
  • 54. Starting the services is easy. We use docker compose up. Stopping is just as easy. Starting and Stopping the Services Start $ docker compose up Stop $ docker compose down
  • 55. Docker Machine — Create and manage Docker environments on virtual machines — Create and manage Docker environments on remote machines — Treat a remote Docker Engine as if it were local
  • 56. Example: Create machine with VirtualBox Create machine $ docker-machine create --driver virtualbox tccc Creating CA: /Users/brianhogan/.docker/machine/certs/ca.pem Creating client certificate: /Users/brianhogan/.docker/machine/certs/cert.pem Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Checking connection to Docker... Docker is up and running! To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env tccc
  • 57. Use Docker Client with New Machine $ docker-machine env tccc export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="/Users/brianhogan/.docker/machine/machines/tccc" export DOCKER_MACHINE_NAME="tccc" # Run this command to configure your shell: # eval $(docker-machine env tccc) $ eval $(docker-machine env tccc)
  • 58. This is an example of using docker machine to create a machine on DigitalOcean. There are other drivers you can use to create machines on other cloud providers. There's also a generic driver you can use if you need to set up machines using your own infrastructure. Example: Create a remote server on DigitalOcean $ docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $DOTOKEN tccc — driver supports cloud providers. Drivers available for Azure and EC2, as well as others. — --digitalocean-image speciïŹes the machine image to use. — $DOTOKEN is an env variable holding an API token — tccc is our machine name.
  • 59. Using the remote machine locally $ docker-machine env tccc export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://45.55.173.165:2376" export DOCKER_CERT_PATH="/Users/brianhogan/.docker/machine/machines/tccc" export DOCKER_MACHINE_NAME="tccc" # Run this command to configure your shell: # eval $(docker-machine env tccc) $ eval $(docker-machine env tccc) You can tell your local Docker client to use your remote machine's docker host as if it were running locally.
  • 60. Deploy App with Compose Switch to the remote machine $ eval $(docker-machine env tccc) Bring up app: $ docker-compose up -d Get the IP $ docker-machine ip tccc
  • 61. When you switch your environment with docker-machine, all docker commands are sent to the remote docker engine. If you want to put things back to point to your local docker engine, you use the -u option. Return back to Local Docker Engine $ docker-machine env -u unset DOCKER_TLS_VERIFY unset DOCKER_HOST unset DOCKER_CERT_PATH unset DOCKER_MACHINE_NAME # Run this command to configure your shell: # eval $(docker-machine env -u) $ eval $(docker-machine env -u)
  • 62. Review — What's the diïŹ€erence between docker-machine and docker-compose? — What does docker-machine env do? — How do you get the IP address of the remote machine?
  • 63. Swarm Mode — Cluster management built in to Docker Engine — Decentralized design with service discovery and multi-host networking — Load balancing and scaling — Replaces Docker Swarm
  • 64. Deploying to a Swarm Mode Cluster — Create the machines with docker-machine — Create at least one swarm master — Create at least one worker — Push your app image to a Docker Registry — Deploy with docker compose
  • 65. Let's create three machines for our swarm. One of these will be the swarm "master", although I like to use the term "swarm boss" instead. The other two will be our workers. We'll create these on DigitalOcean's cloud.. Create a Swarm $ docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $DOTOKEN tccc-boss $ docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $DOTOKEN tccc-worker1 $ docker-machine create --driver digitalocean --digitalocean-image ubuntu-16-04-x64 --digitalocean-access-token $DOTOKEN tccc-worker2
  • 66. First, we create the swarm manager. We have to specify its IP address but we can use docker-machine ip to do that. When we run this command, it'll give us the command to run for each worker. Create a Swarm Manager $ eval "$(docker-machine env tccc-boss)" $ docker swarm init --advertise-addr $(docker-machine ip tccc-boss) Swarm initialized: current node (s4p3vlului2hu8d2beixpu0wa) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-1e60k6k5jmzirfx4bkb3j1pzdsay9ocq5qix0bl91vnuv3ryp3-7o0g6sly1etsxtj33c1hxnoav 192.168.99.101:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
  • 67. To connect each machine, switch your environment to the worker and paste in the command you were given. The token is unique to your swarm, and also identifies the machien as a worker. Swarm masters have a different token. Connect the Workers $ eval "$(docker-machine env tccc-worker1)" $ docker swarm join --token SWMTKN-1-0opi6iq7zh5brglm01m2beeueql9xt0k1tbfx5u6s519inghxr-8mu5o85bxupzp4ykf4shsiifm 192.168.99.101:2377 $ eval "$(docker-machine env tccc-worker2)" $ docker swarm join --token SWMTKN-1-0opi6iq7zh5brglm01m2beeueql9xt0k1tbfx5u6s519inghxr-8mu5o85bxupzp4ykf4shsiifm 192.168.99.101:2377
  • 68. To see the machines in the swarm, switch back to the swarm manager. Then use docker node ls. You'll see which one is the swarm manager. See The Swarm $ eval "$(docker-machine env tccc-worker2)" $ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ofqi7n5u52efec1mjrjxikgxd tccc-worker2 Ready Active s4p3vlului2hu8d2beixpu0wa * tccc-boss Ready Active Leader sc0exb43oafmr307z71bway1s tccc-worker1 Ready Active
  • 69. Swarm mode doesn't allow the build option. We have to specify an image. We don't want to push our image up to a public registry, so we'll just create a registry on our swarm and we'll push it there. Docker Hub is great for public things, but you may not want your app pushed up there because of the cost. So you can create a private registry and push your image there. Change Compose File version: '3' services: app: ++ image: 127.0.0.1:5000/noderedis build: . ports: - "3000:3000" redis: image: redis volumes: - ./data:/data ports: - "6379"
  • 70. Let's test out the app. This will also build the image. You'll see a warning that says it can't deploy to the entire swarm, but that's ok. We're just making sure things build and start. Build with Compose to Test Image $ docker-compose up WARNING: The Docker Engine you're using is running in swarm mode. Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node. To deploy your application across the swarm, use `docker stack deploy`. Creating network "06swarm_default" with the default driver Building app Step 1/10 : FROM node:6 6: Pulling from library/node ... Creating 06swarm_app_1 Creating 06swarm_redis_1
  • 71. There's an official registry image we can use, so we'll use this command to fire up a registry service on our swrm. Then we'll use Compose to push the image up. Create Private Registry $ docker service create --name registry --publish 5000:5000 registry:2 $ docker-compose push
  • 72. Finally, we deploy the stack to the swarm using the compose file. Deploy $ docker stack deploy --compose-file docker-compose.yml noderedis Ignoring unsupported options: build Creating network noderedis_default Creating service noderedis_redis Creating service noderedis_app
  • 73. We can see all of the services running on our swarm with the docker service list command. Our redis server and node app are listed, along with our registry. Review the Nodes $ docker service list ID NAME MODE REPLICAS IMAGE mhnl5pnm5spd noderedis_redis replicated 1/1 redis:latest v9iu32g5eqj1 noderedis_app replicated 1/1 127.0.0.1:5000/noderedis:latest w4x9fep7m5c8 registry replicated 1/1 registry:2
  • 74. To see just the services in the stack we deployed, use the docker stack services command. Explore the stack $ docker stack services noderedis ID NAME MODE REPLICAS IMAGE mhnl5pnm5spd noderedis_redis replicated 1/1 redis:latest v9iu32g5eqj1 noderedis_app replicated 1/1 127.0.0.1:5000/noderedis:latest
  • 75. You can access the swarm using the ip address of the manager or any worker. The mesh network ensures it all works. Access the app $ curl http://<ip_address_of_manager> $ curl http://<ip_address_of_any_worker>
  • 76. Using the docker service ps command you can see what node a service runs on. See where service runs $ docker service ps noderedis_app ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 7rttqwob67qm noderedis_app.1 127.0.0.1:5000/noderedis:latest tccc-worker1 Running Running 10 minutes ago
  • 77. You may want to scale out your app to meet the demand. You can do that with the docker service scale command. ^ You scale up the numbrer of containers we use for our app. I have three machines, and I can scale this app up to three, but that isn't a limitation. I can scale the number of containers to a much higher number than machines. Scale out the app $ docker service scale noderedis_app=3 noderedis_app scaled to 3
  • 78. With the app scaled out, look again at the processes. You can see what nodes each service is running on. Review the Nodes $ docker service ps noderedis_app ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 7rttqwob67qm noderedis_app.1 127.0.0.1:5000/noderedis:latest tccc-worker1 Running Running 12 minutes ago q2pjqf0z8o2w noderedis_app.2 127.0.0.1:5000/noderedis:latest tccc-boss Running Running 6 seconds ago 5oi656f6a0w5 noderedis_app.3 127.0.0.1:5000/noderedis:latest tccc-worker2 Running Running 7 seconds ago
  • 79. All done? Tear it all down by removing the stack. Tear it Down $ docker stack rm noderedis
  • 80. Review — How do you add workers to a swarm? — Can you use docker-compose to push an app to a swarm? — What must you do with your app image in order to deploy with docker-compose?
  • 81. Container Orchestration — Scheduling — (placement, replication / scaling, resurrection, rescheduling, upgrades, downgrades) — Resource management (memory, CPU, volumes, ports, IPs, images) — Service management (i.e. orchestrating several containers together using labels, groups, namespaces, load balancing, readiness checking
  • 83. Rancher Easily deploy and run containers in production on any infrastructure with the most complete container management platform.
  • 84. Kubernetes Open-source system for automating deployment, scaling, and management of containerized applications.
  • 85. Next Steps — These slides (http://bphogan.com/presentations/ docker2017) — DigitalOcean Docker Tutorials (https:// www.digitalocean.com/community/tags/docker? type=tutorials) Questions?