#boscc
Gleb Bahmutov, PhD
Boston Code Camp 2018
It works on my machine ...
This program runs on Ubuntu 12.04
This program runs on Node 8.9
This program requires GunDB (?!)
$ docker run -it ubuntu:12.04
Unable to find image 'ubuntu:12.04' locally
12.04: Pulling from library/ubuntu
d8868e50ac4c: Pull complete
83251ac64627: Pull complete
589bba2f1b36: Pull complete
d62ecaceda39: Pull complete
6d93b41cfc6b: Pull complete
Digest: sha256:18305429af...
Status: Downloaded newer image for ubuntu:12.04
root@58776820952d:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
$ docker run -it ubuntu:12.04
--interactive, -i = session
--tty, -t = start terminal
$ docker run <options> <image name:tag>
$ docker run -it ubuntu:12.04
root@8b9edea5134c:/# echo $SHELL
/bin/bash
(many, many)
images
copied image
container
docker run
$ docker ps
CONTAINER ID IMAGE COMMAND NAMES
8b9edea5134c ubuntu:12.04 "/bin/bash" upbeat_jackson
$ docker run -it --name my-ub ubuntu:12.04
$ docker ps
CONTAINER ID IMAGE COMMAND NAMES
79b05f517c9a ubuntu:12.04 "/bin/bash" my-ub
$ docker stop 79b
79b
Stopping a container
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 12.04 5b117edd0b76 7 months ago 104MB
$ docker rmi ubuntu:12.04
Error response from daemon: conflict:
unable to remove repository reference
"ubuntu:12.04" (must force) - container b0ffbace152d
is using its referenced image 5b117edd0b76
Need to delete all containers (even stopped) that reference the image "ubuntu:12.04"
Removing an image
CONTAINER ID IMAGE STATUS NAMES
79b05f517c9a ubuntu:12.04 Exited (137) 6 minutes ago my-ub
8b9edea5134c ubuntu:12.04 Exited (0) 10 minutes ago upbeat_jackson
3246d0e8230a ubuntu:12.04 Exited (0) 22 minutes ago cranky_benz
b0ffbace152d ubuntu:12.04 Exited (127) 24 minutes ago thirsty_kalam
58776820952d ubuntu:12.04 Exited (0) 24 minutes ago nostalgic_bardeen
$ docker ps -a --filter ancestor=ubuntu:12.04
$ docker rm 79b05f517c9a 8b9edea5134c ...
$ docker rm 79b 8b9 ...
$ docker rm $(docker ps -a --filter ancestor=ubuntu:12.04 -q)
58776820952d
b0ffbace152d
...
Removing found images
$ ls .
index.js package.json
$ cat index.js
console.log('node version', process.version)
$ docker run -v $PWD:/src -w /src -it node:8.9 /bin/bash
root@513ed6d3776d:/src# ls
index.js package.json
root@513ed6d3776d:/src# node index.js
node version v8.9.1
-v host:container = attach volume
-w path = working folder
docker:
- image: node:8.9
CircleCI
Codeship
GitLabCI
...
$ docker run -p 8080:8080 gundb/gun
Unable to find image 'gundb/gun:latest' locally
latest: Pulling from gundb/gun
...
Server started on port 8080 with /gun
Then open localhost:8080
-p host_port:container_port = map port
FROM gundb/gun:0.8
Dockerfile
$ docker build -t gleb/my-gun:0.8 .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM gundb/gun:0.8
---> c88081efafb3
Successfully built c88081efafb3
Successfully tagged gleb/my-gun:0.8
--tag, -t <name> = tag image
Personal Docker cheatsheet
$ docker run -it -p 9000:8080 gleb/my-gun:0.8
Then open localhost:9000
FROM mhart/alpine-node:8
WORKDIR /app
COPY . .
RUN npm install
RUN npm run lint
RUN npm test
EXPOSE 1337
CMD ["node", "index.js"]
docker history <image name>
0dc9a45a3171
8b66fb0060f5
79a9d606ae3c
300beaa8696b
a17394505502
e6ebb0e80ecb
343874389450
2777ecbd35ff
$ docker images gleb/hello-world
REPOSITORY TAG IMAGE ID SIZE
gleb/hello-world bare 78cdddcd77ac 37.9MB
gleb/hello-world multi-stage 44dcd42b11f4 49.4MB
gleb/hello-world simple aed28e2bde45 202MB
$ ls
Dockerfile
$ cat Dockerfile
FROM gundb/gun:0.8
$ now
> Deploying ~/git/training-github/docker/gun-test under bahmutov
> Ready! https://gun-test-dlusfciqnx.now.sh (copied to clipboard) [3s]
> Synced 1 file (19B) [0ms]
> Initializing…
> Building
> ▲ docker build
...
> Successfully built c88081efafb3
> ▲ Storing image
> ▲ Deploying image
> ▲ Container started
with Zeit.co Now tool
$ time now
...
real 0m18.863s
$ wget https://raw.githubusercontent.com/dokku/dokku/v0.10.5/bootstrap.sh
$ sudo DOKKU_TAG=v0.10.5 bash bootstrap.sh
root@gleb-demos:~# dokku apps:create my-gun
Creating my-gun... done
$ git push dokku master
Counting objects: 3, done.
Writing objects: 100% (3/3), 236 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
-----> Cleaning up...
-----> Building my-gun from dockerfile...
remote: build context to Docker daemon 2.048kB
Step 1/1 : FROM gundb/gun:0.8
...
=====> Application deployed:
http://my-gun.gleb-demos.com
http://my-gun.gleb-demos.com:8080
$ git remote add dokku dokku@gleb-demos.com:my-gun
Learn Docker and k8s at www.katacoda.com
Use images from Docker Hub
Build your own images
Deploy using Zeit Now or Dokku
If server is not working, fix <code, Dockerfile, environment variables> and deploy new server
#boscc