Docker

Docker: COMANDOS básicos com EXEMPLOS que vão te AJUDAR no dia a dia

Bora
docker images
Containers
# docker run centos
Unable to find image 'centos:latest' locally
latest: Pulling from library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for centos:latest
# docker run --rm -ti  ubuntu:16.04
# docker run --name testemedium -tid ubuntu:18.04
# docker run ubuntu:17.10 ps aux
Unable to find image 'ubuntu:17.10' locally
17.10: Pulling from library/ubuntu
4ccdce43d1e0: Already exists
c95f13c88d92: Already exists
82656eee95ad: Already exists
78ff727be57a: Already exists
448bb314afa5: Already exists
Digest: sha256:3b811ac794645dfaa47408f4333ac6e433858ff16908965c68f63d5d315acf94
Status: Downloaded newer image for ubuntu:17.10
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 30520 1652 ? Rs 14:15 0:00 ps aux
# docker run --name ping -d busybox ping 127.0.0.1 -c 15
# docker stop 419b4f6a34e8
# docker rm 419b4f6a34e8
419b4f6a34e8
# docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
7d75b0ed36d5015070b745194722020ce62f097255260320561bebd569f4a10f
33c9bed76c2114dcffb4a8f55e7c9a910ee9530fd3fc25d677f216f8c6f23139
50a74a9a19fc784aac3cc5a888b614b5a267fdda1486a6a3b2e4d51f199d87c0
be55837ab14faadd0d7151eec713d9abbd9dbe57688043a34d01bd227eb33414
31e828a5bcb8fdb7cc2d48ed162a0ac7b6326ed9dfdb73cc9edcf634e0df2daa
aa75fcc715fc5462a40ff703516da1a7e9afc7327bf6da8ab03b419e11fc003b
c35db081a3e76cf0ed5635f482573ae9420246185494ef703575a3f35fc7eea0
bd54f7fd3dcea4f96daddbb086c1ffb7cffc3b6e8fe95ea62e1d2d5fd7228a3d
c4340a98c2418929074d3ee924929f606e5f0d726ac66022291830fee5b3b31a
2960e9caae7b33bc076314909973b5717e6f954ca97b8018fc2b068c51ac77d4
5df3d83d2d6a0b6a36da6a02eb2feba66921f443d6b13eb50b3996d60880e264
185f0decc130c666e0246869d5271a40570f6d49e75578df0e3f8fe19400b0cc
# docker run --name logs -d busybox ping 127.0.0.1 -c 15
# docker logs logs
PING 127.0.0.1 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.051 ms
64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.080 ms
64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.084 ms
64 bytes from 127.0.0.1: seq=3 ttl=64 time=0.106 ms
64 bytes from 127.0.0.1: seq=4 ttl=64 time=0.041 ms
64 bytes from 127.0.0.1: seq=5 ttl=64 time=0.073 ms
64 bytes from 127.0.0.1: seq=6 ttl=64 time=0.079 ms
64 bytes from 127.0.0.1: seq=7 ttl=64 time=0.075 ms
64 bytes from 127.0.0.1: seq=8 ttl=64 time=0.079 ms
64 bytes from 127.0.0.1: seq=9 ttl=64 time=0.064 ms
64 bytes from 127.0.0.1: seq=10 ttl=64 time=0.058 ms
64 bytes from 127.0.0.1: seq=11 ttl=64 time=0.067 ms
64 bytes from 127.0.0.1: seq=12 ttl=64 time=0.059 ms
64 bytes from 127.0.0.1: seq=13 ttl=64 time=0.090 ms
64 bytes from 127.0.0.1: seq=14 ttl=64 time=0.070 ms
--- 127.0.0.1 ping statistics ---
15 packets transmitted, 15 packets received, 0% packet loss
round-trip min/avg/max = 0.041/0.071/0.106 ms
# docker info
Client:
Debug Mode: false
Server:
Containers: 5
Running: 0
Paused: 0
Stopped: 5
Images: 5
Server Version: 19.03.3
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: b34a5c8af56e510852c35414db4c1f4fa6172339
runc version: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
init version: fec3683
# docker attach nervous_lovelace
# docker exec nervous_lovelace ps axu
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 18220 3220 pts/0 Ss+ 10:38 0:00 /bin/bash
root 11 0.0 0.0 34660 2736 ? Rs 10:45 0:00 ps axu
# docker exec -d nervous_lovelace touch /tmp/teste123
# docker exec nervous_lovelace ls /tmp
teste123
# docker exec -ti nervous_lovelace bash
docker cp nervous_lovelace:/tmp/teste123 .

Senior Linux Administrator @IBM

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store