run and operate containers

docker 

Management Commands:
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  volume      Manage volumes
docker 

docker version 

docker -v 

docker system info 

docker system events
docker image ls 

docker image pull  alpine:3.12

docker image ls

Launching Container

image

app

docker
container
run
alpine:3.12
uptime

(environment)

image format

registry.docker.io

registry

namespace

repository

tag

/user
/ubuntu
:20.04

Launching Container

docker
run
alpine:3.12
uptime
  • image pull
  • container create
  • container attach
  • network connect
  • container start
  • container die
  • network disconnet

Events

what happened to the container? 

docker container  ps 

docker container  ps -l

Docker containers last only till

the program you started with it

lasts. It will stop immediately

after the program exits.

Run additional containers

docker run alpine:3.12 hostname

docker run alpine:3.12 ps aux 

docker run alpine:3.12 ifconfig

listing containers

docker  ps

docker  ps -l 

docker  ps -n 2 

docker  ps -a

interactive mode

docker  container run  -i -t alpine:3.12 sh

interactive

allocate TTY

open shell

Namespaced

non namespaced

running Commands inside container
cat /etc/issue

ps aux 

ifconfig

hostname
uptime 

uname -a 

cat /proc/cpuinfo

date

free

making containers persist

docker container run 

detach

image

app/program

-idt
schoolofdevops/loop
program

(persistent)

--name loop

Checking app Logs

docker ps 
[note container’s name/id ]

docker logs loop 

docker logs -f loop 

[this command will follow the logs and 
will show you as they update. 
Use ^c to stop following. ]

getting inside container's shell

docker ps 
[note container name/id]

[to run a  one-off  command]
docker exec loop uptime

[for getting a shell access inside the container]
docker exec -it loop sh

modifying containers

docker container run -idt --name redis --rm -it  ubuntu bash
apt-get update
apt-cache search redis
apt-get install redis
redis-server

Inside container's shell

docker run -idt -p 8000:80  --rm schoolofdevops/vote

port mapping

port mapping

docker  ps 
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
f6ce11cb529b        schoolofdevops/vote         "gunicorn app:app ..."   54 seconds ago      Up 52 seconds       0.0.0.0:32776->80/tcp                                              cranky_poitras

80

32768

32769

docker host

mac/win

80

docker port <container id/name>

http://docker_host_ip:hostport

To access web app

renaming

docker container rename  <container id/name> vote

inspect

docker container inspect vote

See if you could find the 

  • logpath
  • mount points
  • ip address

copying files

touch localfile
docker cp localfile vote:/tmp/
docker cp vote:app .
docker diff vote
docker diff stats
  • A : Added
  • C : Changed
  • D : Deleted

Limiting resources

run stats

docker  stats

(^c to exit)

docker  stats --no-stream=true 
 

stats command is based on cgroups.  cgroups provide accounting of resources in addition to setting resource limits

Updating memory

docker container inspect vote | grep -i memory

docker container stats --no-stream=true
docker update --memory 400M  --memory-swap -1 vote

docker container stats --no-stream=true
[CPU Shares]

docker run -d --cpu-shares 1024 schoolofdevops/stresstest stress --cpu 2

docker run -d --cpu-shares 1024 schoolofdevops/stresstest stress --cpu 2

docker run -d --cpu-shares 512 schoolofdevops/stresstest stress --cpu 2

docker run -d --cpu-shares 512 schoolofdevops/stresstest stress --cpu 2

docker run -d --cpu-shares 4096 schoolofdevops/stresstest stress --cpu 2


[CPUs]

docker run -d --cpus 0.2 schoolofdevops/stresstest stress --cpu 2

Launch containers with --cpu-shares

controlling CPU

Managing Container’s Lifecycle

docker create -it --name twostep ubuntu bash 

docker start twostep


docker stop twostep  


docker stop container_id  container_id  container_id 


docker start twostep 


docker rm twostep 


docker rm -f  vote 

pruning

docker system df

docker [ system | container | image ]  prune 

docker container prune


D102: Operating Docker

By School of Devops

D102: Operating Docker

Docker Getting Started

  • 1,659