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
image
app
docker
container
run
alpine:3.12
uptime
(environment)
registry.docker.io
registry
namespace
repository
tag
/user
/ubuntu
:20.04
docker
run
alpine:3.12
uptime
image pull
container create
container attach
network connect
container start
container die
network disconnet
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.
docker run alpine:3.12 hostname
docker run alpine:3.12 ps aux
docker run alpine:3.12 ifconfig
docker ps
docker ps -l
docker ps -n 2
docker ps -a
docker container run -i -t alpine:3.12 sh
interactive
allocate TTY
open shell
running Commands inside container
cat /etc/issue
ps aux
ifconfig
hostname
uptime
uname -a
cat /proc/cpuinfo
date
free
docker container run
detach
image
app/program
-idt
schoolofdevops/loop
program
(persistent)
--name loop
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. ]
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
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
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
docker container rename <container id/name> vote
docker container inspect vote
See if you could find the
touch localfile
docker cp localfile vote:/tmp/
docker cp vote:app .
docker diff vote
docker diff stats
A : Added
C : Changed
D : Deleted
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
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
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
docker system df
docker [ system | container | image ] prune
docker container prune