Kreirano 2024-09-30 Mon 13:39, pritisni ESC za mapu, m za meni, Ctrl+Shift+F za pretragu
$ docker run ubuntu:16.04 /bin/echo 'Hello world' Hello world
$ docker run -t -i ubuntu:16.04 /bin/bash root@af8bae53bdd3:/#
-t
- alokacija pseudo terminala-i
- spajanje na STDIN
root@af8bae53bdd3:/# pwd / root@af8bae53bdd3:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@af8bae53bdd3:/# exit
$ docker run -d ubuntu:16.04 /bin/sh -c "while true; do echo hello world; sleep 1; done" 1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1e5535038e28 ubuntu:16.04 /bin/sh -c 'while tr 2 minutes ago Up 1 minute insane_babbage $ docker logs insane_babbage hello world hello world hello world $ docker stop insane_babbage insane_babbage $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-d
| --detach
- ne “kačiti” se za STDOUTPython Flask
aplikacije.$ docker run -d -P training/webapp python app.py $ docker ps -l CONTAINER ID IMAGE COMMAND CREATED bc533791f3f5 training/webapp:latest python app.py 5 seconds ago STATUS PORTS NAMES Up 2 seconds 0.0.0.0:49155->5000/tcp nostalgic_morse
-P
- Mapiranje porta iz intervala 32768-61000 na exportovane portove
kontejnera$ docker run -d -p 80:5000 training/webapp python app.py
$ docker-machine ip my-docker-vm 192.168.99.100
$ docker port nostalgic_morse 5000 0.0.0.0:49155
$ docker logs -f nostalgic_morse * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) 172.17.0.1 - - [15/Dec/2016 15:14:20] "GET / HTTP/1.1" 200 - 172.17.0.1 - - [15/Dec/2016 15:14:20] "GET /favicon.ico HTTP/1.1" 404 - 172.17.0.1 - - [15/Dec/2016 15:14:20] "GET /favicon.ico HTTP/1.1" 404 -
-f
“forever” - terminal ostaje “zakačen” na STDOUT kontejnera$ docker top nostalgic_morse UID PID PPID C STIME TTY TIME CMD root 20409 20393 0 16:10 ? 00:00:00 python app.py
$ docker stats --no-stream nostalgic_morse CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS elegant_meitner 0.02% 24.06 MiB / 7.493 GiB 0.31% 3.895 kB / 3.686 kB 13.33 MB / 0 B 1
--no-stream
- vrati prvi rezultat$ docker inspect nostalgic_morse [ { "Id": "650bf9569f884b0bbb1274c0af88b002b4e5e6556438484ae79dcd275a4f7930", "Created": "2016-12-15T15:10:53.460834861Z", "Path": "python", "Args": [ "app.py" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 20409, . . .
-t -i
parametara, konzola se može “otkačiti” sa Ctrl-P-Q
.$ docker attach nostalgic_morse
shell
. U tom slučaju ukoliko se povežemo sa
attach
nemamo interakciju već imamo samo ispis aplikacije koja se izvršava.$ docker exec -it mycontainer bash root@bd57610aa95a:/usr/src/redmine#
exit
ili Ctrl-D
.$ docker stop nostalgic_morse nostalgic_morse $ docker rm nostalgic_morse nostalgic_morse
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 16.04 1d073211c498 3 days ago 187.9 MB busybox latest 2c5ac3f849df 5 days ago 1.113 MB training/webapp latest 54bb4e8718e8 5 months ago 348.7 MB
$ docker run -t -i ubuntu:12.04 /bin/bash
latest
.run
komanda će automatski preuzeti sliku ukoliko ne postoji lokalno.docker pull
.$ docker pull centos Pulling repository centos b7de3133ff98: Pulling dependent layers 5cc9e91966f7: Pulling fs layer 511136ea3c5a: Download complete ef52fb1fe610: Download complete . . . Status: Downloaded newer image for centos $ docker run -t -i centos /bin/bash bash-4.1#
docker search
komande.$ docker search sinatra NAME DESCRIPTION STARS OFFICIAL AUTOMATED erikap/ruby-sinatra Docker for hosting Sinatra apps 12 [OK] semtech/mu-sinatra-template Template for running Ruby/Sinatra microser... 2 [OK] zyio/sinatra Tiny-ish Sinatra Dockerfile 1 [OK] samlet/microservices-sinatra-products microservices with sinatra 1 [OK] lucymhdavies/sinatra-boilerplate Docker image with my boilerplate for Sinat... 1 [OK] thomastanmin/sinatra This is the docker example with auto build... 1 [OK] tdiary/rpaproxy-sinatra 1 [OK] convox/sinatra Convox base image for Sinatra 0 [OK] . . .
OFFICIAL
- Podrška od strane Docker, Inc.AUTOMATED
- Automatizovana izgradanja sa GitHub ili Bitbucket-a.ubuntu
).training/sinatra
). Izgrađeni i podržani od strane članova doker zajednice.$ docker pull training/sinatra $ docker run -t -i training/sinatra /bin/bash root@a8cb6ce02d85:/#
commit
operacijom.Dockerfile
fajla koji opisuje postupak izgradnje nove slike
polazeći od postojeće i primenom niza komandi.$ docker run -t -i training/sinatra /bin/bash root@0b2616b0e5a8:/# root@0b2616b0e5a8:/# gem install json ... root@0b2616b0e5a8:/# exit $ docker commit -m "Added json gem" -a "Kate Smith" 0b2616b0e5a8 ouruser/sinatra:v2 4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c
-m
- commit poruka-a
- autor$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE training/sinatra latest 5bc342fa0b91 10 hours ago 446.7 MB ouruser/sinatra v2 3c59e02ddd1a 10 hours ago 446.7 MB ouruser/sinatra latest 5db5f8471261 10 hours ago 446.7 MB $ docker run -t -i ouruser/sinatra:v2 /bin/bash root@78e82f680994:/#
Dockerfile
fajla$ mkdir sinatra $ cd sinatra $ touch Dockerfile
Sadržaj fajla:
# This is a comment
FROM ubuntu:14.04
MAINTAINER Kate Smith <ksmith@example.com>
RUN apt-get update && apt-get install -y ruby ruby-dev
RUN gem install sinatra
build
komanda$ docker build -t ouruser/sinatra:v2 . Sending build context to Docker daemon 2.048 kB Sending build context to Docker daemon Step 1 : FROM ubuntu:14.04 --->; e54ca5efa2e9 Step 2 : MAINTAINER Kate Smith <ksmith@example.com> --->; Using cache --->; 851baf55332b Step 3 : RUN apt-get update && apt-get install -y ruby ruby-dev --->; Running in 3a2558904e9b Selecting previously unselected package libasan0:amd64. (Reading database ... 11518 files and directories currently installed.) ... Removing intermediate container 3a2558904e9b Step 4 : RUN gem install sinatra ---> Running in 6b81cb6313e5 Successfully installed rack-1.5.2 Successfully installed tilt-1.4.1 ... Removing intermediate container 6b81cb6313e5 Successfully built 97feabe5d2ed
Dockerfile
ali može imati i dodatne fajlove
i foldere koji se mogu po potrebi ugraditi u kontejner komandom ADD
.Napomena: Celokupan folder se pakuje i šalje demon procesu. Paziti da folder sadrži samo zaista potrebne fajlove.
$ docker tag 5db5f8471261 ouruser/sinatra:devel $ docker images ouruser/sinatra REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ouruser/sinatra latest 5db5f8471261 11 hours ago 446.7 MB ouruser/sinatra devel 5db5f8471261 11 hours ago 446.7 MB ouruser/sinatra v2 5db5f8471261 11 hours ago 446.7 MB
$ docker push ouruser/sinatra The push refers to a repository [ouruser/sinatra] (len: 1) Sending image list Pushing repository ouruser/sinatra (3 tags) . . .
$ docker rmi training/sinatra Untagged: training/sinatra:latest Deleted: 5bc342fa0b91cabf65246837015197eecfa24b2213ed6a51a8974ae250fedd8d Deleted: ed0fffdcdae5eb2c3a55549857a8be7fc8bc4241fb19ad714364cbfd7a56b22f Deleted: 5c58979d73ae448df5af1d8142436d81116187a7633082650549c52c3a2418f0
dockviz
$ docker pull nate/dockviz Using default tag: latest latest: Pulling from nate/dockviz 8bd831364921: Pull complete 3dfb5e1486b5: Pull complete 607d274e6daa: Pull complete Digest: sha256:9afe152b794ae8480b230545ec75bc81f5e11a0b9d28158bb609479de5a95a72 Status: Downloaded newer image for nate/dockviz:latest $ alias dockviz="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz"
$ dockviz containers -d | dot -Tpng -o containers.png
$ dockviz images -t -i └─511136ea3c5a Virtual Size: 0.0 B ├─f10ebce2c0e1 Virtual Size: 103.7 MB │ └─82cdea7ab5b5 Virtual Size: 255.5 KB │ └─5dbd9cb5a02f Virtual Size: 1.9 KB │ └─74fe38d11401 Virtual Size: 105.7 MB Tags: ubuntu:12.04, ubuntu:precise ├─ef519c9ee91a Virtual Size: 100.9 MB │ └─07302703becc Virtual Size: 251.0 KB │ └─cf8dc907452c Virtual Size: 1.9 KB │ └─a7cf8ae4e998 Virtual Size: 70.1 MB Tags: ubuntu:12.10, ubuntu:quantal │ ├─e18d8001204e Virtual Size: 29.4 KB │ │ └─d0525208a46c Virtual Size: 71.0 B │ │ └─59dac4bae93b Virtual Size: 71.2 MB │ │ └─89541b3b35f2 Virtual Size: 269.3 MB │ │ └─7dac4e98548e Virtual Size: 0.0 B │ │ └─341d0cc3fac8 Virtual Size: 0.0 B ...