docker: run ubuntu interactively

Lets get the output of top from ubuntu container

$ sudo docker container run -it ubuntu top

$ sudo docker container run -it ubuntu top
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
da7391352a9b: Pull complete 
14428a6d4bcd: Pull complete 
2c2d948710f2: Pull complete 
Digest: sha256:c95a8e48bf88e9849f3e0f723d9f49fa12c5a00cfc6e60d2bc99d87555295e4c
Status: Downloaded newer image for ubuntu:latest

top - 03:16:26 up 13 days, 3 min,  0 users,  load average: 0.48, 0.39, 0.37
Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni, 99.3 id,  0.7 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  11831.3 total,    209.7 free,   4562.1 used,   7059.4 buff/cache
MiB Swap:   6125.0 total,   6065.5 free,     59.5 used.   6772.2 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                              
      1 root      20   0    6188   3232   2764 R   0.0   0.0   0:00.04 top   

Now interact with ubuntu container in several ways

$ sudo docker container exec d49b5a735ee0 ls
bin
boot
dev
etc
home
lib
lib32
lib64
libx32
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

Or other commands

$ sudo docker container exec d49b5a735ee0 pwd
/

And to connect directly to the bash terminal

$ sudo docker container exec -it d49b5a735ee0 bash
root@d49b5a735ee0:/# 
root@d49b5a735ee0:/# 
root@d49b5a735ee0:/# pwd
/
root@d49b5a735ee0:/# ls
bin  boot  dev  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@d49b5a735ee0:/# ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 03:17 pts/0    00:00:00 top
root          22       0  0 03:20 pts/1    00:00:00 bash
root          30      22  0 03:20 pts/1    00:00:00 ps -ef

RELATED POST

Veritas Volume Manager: Growing a disk group and expand the filesystem

Validated by Mr Man! Lets start off on node2 [root@node02 ~]# vxdisk list DEVICE TYPE DISK GROUP STATUS sda auto:none…

Virtual Machine Manager: Error starting domain

Starting up the KVM error occurred Error starting domain: Requested operation is not valid: network 'default' is not active Locate…

Lab Hack: Raspberry Pi running VMWare ESXi

As strange as the title sounds, yes I am running VMWare ESXi on a Raspberry Pi 4 Model B (4GB)…

Lab Hack: Ubuntu openssh-server and passwordless authentication

While setting up the lab for a docker swarm training module I decided to spin up a few vms in…