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
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
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