Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Docker on
Command Line
Do you know what command line is?
Docker on Command Line
Command line. The most efficient way to use Docker.
● Your Containers and Images
● Working with a Registry
● Running and executing containers
● Build your own containers
● Container management
$ docker
Run this
Docker Help
All possible commands.
$ docker help run
● Container is a runnable artifact.
● Images are a copy of a filesystem.
● You can run an image inside a container.
You start from someone elses image
and build on top of that!
Your Containers and Images
Working with a Registry
All installs are by default connected to Docker Hub
$ docker pull, commit, push
Git-like commands for working with a container and a registry.
$ docker login
$ docker pull
Run this
Choosing Containers
● Docker Hub (https://hub.docker.com)
● Smaller = better (generally) - Love Alpine.
● Official containers and non-official containers
● Check out how they are built
You should all star my projects ;-)
Running a container
Run container is to start it.
$ docker run
At this point you would add extra detail to the command to make it
(connect to ports, mount volumes).
$ docker run -p 8080:80 -v $(pwd):/app nginx:alpine
$ docker run
Run this
Execute into a running container
Exec to a container is to execute a program inside it.
$ docker exec
Whatever goes after the docker command will try to run on the
system (depending on the endpoint - which we will discuss later).
$ docker -it exec [container] /bin/sh
$ docker exec
Run this
Build your own images
Using Dockerfile you can build your own images
$ docker build
This is defined and created in layers.
$ docker build -t i-love-containers .
Dockerfile
Make this
$ vim index.html
PRESS: i (enter [INSERT] mode)
<h1>I LOVE CONTAINERS</h1>
PRESS: [Esc]
Type: :wq
Or write on your local machine and drag into browser window.
$ vim Dockerfile
FROM nginx:latest
COPY ./index.html /usr/share/nginx/html/index.html
$docker build
Run this
$ docker build
$ docker build -t i-love-containers .
$docker run
Run this
$ docker run
$ docker run -p 8082:80 i-love-containers
Run your app
Run this
JavaScript (package.json)
{
"name": "i-love-containers",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3"
}
}
JavaScript (index.js)
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('I Love JS Containers!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Run it
$ docker run -it -p 3000:3000 -v $(pwd):/app node:8-
alpine /bin/sh
$ cd /app
$ npm install
$ node index.js
Dockerfile
FROM node:8-alpine
COPY ./ /app
RUN cd /app && npm install
EXPOSE 3000
CMD ["node", "/app/index.js"]
Build it & Run it
$ docker build -y i-love-js-containers
$ docker run -d -p 3000:3000 i-love-js-containers
CONNECT WITH
ME…
Will Hall
Digital Architect
@hn_will
www.linkedin.com/in/willhallonline
www.willhallonline.co.uk

More Related Content

Docker Command Line, Using and Choosing containers

  • 1. Docker on Command Line Do you know what command line is?
  • 2. Docker on Command Line Command line. The most efficient way to use Docker. ● Your Containers and Images ● Working with a Registry ● Running and executing containers ● Build your own containers ● Container management
  • 4. Docker Help All possible commands. $ docker help run
  • 5. ● Container is a runnable artifact. ● Images are a copy of a filesystem. ● You can run an image inside a container. You start from someone elses image and build on top of that! Your Containers and Images
  • 6. Working with a Registry All installs are by default connected to Docker Hub $ docker pull, commit, push Git-like commands for working with a container and a registry. $ docker login
  • 8. Choosing Containers ● Docker Hub (https://hub.docker.com) ● Smaller = better (generally) - Love Alpine. ● Official containers and non-official containers ● Check out how they are built You should all star my projects ;-)
  • 9. Running a container Run container is to start it. $ docker run At this point you would add extra detail to the command to make it (connect to ports, mount volumes). $ docker run -p 8080:80 -v $(pwd):/app nginx:alpine
  • 11. Execute into a running container Exec to a container is to execute a program inside it. $ docker exec Whatever goes after the docker command will try to run on the system (depending on the endpoint - which we will discuss later). $ docker -it exec [container] /bin/sh
  • 13. Build your own images Using Dockerfile you can build your own images $ docker build This is defined and created in layers. $ docker build -t i-love-containers .
  • 15. $ vim index.html PRESS: i (enter [INSERT] mode) <h1>I LOVE CONTAINERS</h1> PRESS: [Esc] Type: :wq Or write on your local machine and drag into browser window.
  • 16. $ vim Dockerfile FROM nginx:latest COPY ./index.html /usr/share/nginx/html/index.html
  • 18. $ docker build $ docker build -t i-love-containers .
  • 20. $ docker run $ docker run -p 8082:80 i-love-containers
  • 22. JavaScript (package.json) { "name": "i-love-containers", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "express": "^4.16.3" } }
  • 23. JavaScript (index.js) var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('I Love JS Containers!'); }); app.listen(3000, function () { console.log('Example app listening on port 3000!'); });
  • 24. Run it $ docker run -it -p 3000:3000 -v $(pwd):/app node:8- alpine /bin/sh $ cd /app $ npm install $ node index.js
  • 25. Dockerfile FROM node:8-alpine COPY ./ /app RUN cd /app && npm install EXPOSE 3000 CMD ["node", "/app/index.js"]
  • 26. Build it & Run it $ docker build -y i-love-js-containers $ docker run -d -p 3000:3000 i-love-js-containers
  • 27. CONNECT WITH ME… Will Hall Digital Architect @hn_will www.linkedin.com/in/willhallonline www.willhallonline.co.uk