Thursday, April 6, 2023

DOCKER COMMANDS HANDS-ON

 



 Each lab scenario gives you the opportunity to familiarize with the set up.  You will be expected to perform tasks like run a container, build, delete and stop. 

STEP 1: 
Docker  Version : To check the version of Docker Server Engine running on the host.

The output will show you both the client and server version of Docker engine installed on your system. 

$ docker version
Client: Docker Engine - Community
Version: 19.03.15
API version: 1.40
Go version: go1.13.15
Git commit: 99e3ed8919
Built: Sat Jan 30 03:17:11 2021
OS/Arch: linux/amd64
Experimental: false

Server: Docker Engine - Community
Engine:
Version: 19.03.15
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 99e3ed8919
Built: Sat Jan 30 03:15:40 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.18.0
GitCommit: fec3683
$




STEP 2:
How many images are available ? You run the command docker images

$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 4f06b49211c0 5 weeks ago 530MB
nginx alpine 2bc7edbc3cf2 7 weeks ago 40.7MB
postgres latest 680aba37fd0f 7 weeks ago 379MB
alpine latest b2aa39c304c2 7 weeks ago 7.05MB
redis latest 2f66aad5324a 7 weeks ago 117MB
nginx latest 3f8a00f137a0 7 weeks ago 142MB
ubuntu latest 58db3edaf2be 2 months ago 77.8MB


STEP 3:
You can run a container using the redis image. 


$ docker run -t redis
1:C 05 Apr 2023 16:10:51.377 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 05 Apr 2023 16:10:51.377 # Redis version=7.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 05 Apr 2023 16:10:51.377 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 05 Apr 2023 16:10:51.378 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 7.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'


STEP 4:
docker run redis 

$ docker run redis
1:C 05 Apr 2023 16:55:43.279 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 05 Apr 2023 16:55:43.279 # Redis version=7.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 05 Apr 2023 16:55:43.279 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /pa

STEP 5:
Can you stop the running container you just created. 


$ docker stop 8413d7fdbfdb
8413d7fdbfdb
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8413d7fdbfdb redis "docker-entrypoint.s…" 5 minutes ago Exited (0) 10 seconds ago jolly_nightingale


STEP 6:
To check the running container. 

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$


STEP 7:
How many containers are present on the host including both running and not running ones.

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8413d7fdbfdb redis "docker-entrypoint.s…" 5 minutes ago Exited (0) 10 seconds ago jolly_nightingale
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8413d7fdbfdb redis "docker-entrypoint.s…" 8 minutes ago Exited (0) 3 minutes ago jolly_nightingale
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37bf0d26e4c1 alpine "/bin/sh" About a minute ago Exited (0) About a minute ago charming_cori
cd25b2b81889 alpine "sleep 1000" About a minute ago Up About a minute pedantic_kapitsa
f30f483b1c0a nginx:alpine "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp nginx-2
d74280453797 nginx:alpine "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp nginx-1
c841b3e99c4a ubuntu "sleep 1000" About a minute ago Up About a minute awesome_northcut
8413d7fdbfdb redis "docker-entrypoint.s…" 11 minutes ago Exited (0) 5 minutes ago jolly_nightingale
$



STEP 8:
To stop the container you just created.

$ docker stop 2f791
2f791
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2f791c2115ff redis "docker-entrypoint.s…" 7 minutes ago Exited (0) 6 minutes ago competent_cartwright
$

STEP 9:
To stop containers run the command "docker stop (container id) (container name) and then to delete them run docker rm (container id)

$ docker stop 86eff91657af crazy_meitner
86eff91657af
crazy_meitner
$ docker rm 86eff91657af
86eff91657af
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef7675b669eb nginx:alpine "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 80/tcp nginx-2
998bd5125c4d nginx:alpine "/docker-entrypoint.…" 10 minutes ago Up 10 minutes 80/tcp nginx-1
5792f6aaa0b0 ubuntu "sleep 1000" 11 minutes ago Up 10 minutes awesome_northcut
2a0ee489807d redis "docker-entrypoint.s…" 12 minutes ago Exited (0) 11 minutes ago ecstatic_darwin
2f791c2115ff redis "docker-entrypoint.s…" 24 minutes ago Exited (0) 23 minutes ago competent_cartwright
$ docker stop ef7675b669eb nginx-2
ef7675b669eb
nginx-2
$ docker rm ef7675b669eb
ef7675b669eb
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
998bd5125c4d nginx:alpine "/docker-entrypoint.…" 12 minutes ago Up 12 minutes 80/tcp nginx-1
5792f6aaa0b0 ubuntu "sleep 1000" 12 minutes ago Up 12 minutes awesome_northcut
2a0ee489807d redis "docker-entrypoint.s…" 14 minutes ago Exited (0) 13 minutes ago ecstatic_darwin
2f791c2115ff redis "docker-entrypoint.s…" 26 minutes ago Exited (0) 25 minutes ago competent_cartwright
$


STEP 10:
To delete an ubutu image. The command is "docker rmi ubuntu"

$ docker rmi ubuntu
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:9a0bdde4188b896a372804be2384015e90e3f84906b750c1a53539b585fbbe7f


STEP 11:
To pull an image. 

$ docker pull nginx:1.14-alpine
1.14-alpine: Pulling from library/nginx
bdf0201b3a05: Pull complete
3d0a573c81ed: Pull complete
8129faeb2eb6: Pull complete
3dc99f571daf: Pull complete
Digest: sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Status: Downloaded newer image for nginx:1.14-alpine
docker.io/library/nginx:1.14-alpine
$


STEP 12:
You can run a container with the nginx:1.14-alpine image and name it webapp .

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker run -d --name webapp nginx:1.14-alpine
3b1729e87ea63258d4a99d95ee7481f35fccdd83a95f8fa7ec3dc8d131879d80
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b1729e87ea6 nginx:1.14-alpine "nginx -g 'daemon of…" 9 seconds ago Up 7 seconds 80/tcp webapp
$
Kode kloud
Next slide we will discuss on docker run . Happy Learning !!! ðŸ˜Š

No comments:

Post a Comment

CONFIGURING A PHISHING CAMPAIGN IN MICROSOFT DEFENDER.

Configuring a phishing campaign in Microsoft Defender (specifically Microsoft Defender for Office 365) involves creating a simulated attack ...