4. DevOps: How to create and work with Docker Containers

Docker-logo

In continuation of my previous blog on 2. DevOps: How to install Docker 17.03.0 community edition and start working with it on Ubuntu 16.x VM [https://vskumar.blog/2017/11/25/2-devops-how-to-install-docker-17-03-0-community-edition-and-start-working-with-it-on-ubuntu-16-x-vm/], in this blog I would like to cover the lab practice on Docker containers.

Assuming you have the same setup as we did in the previous lab session,

using the below subcommand, you can view the current image hello-world

$docker history hello-world

You can run this image and see:

======================>

vskumar@ubuntu:~$ sudo docker history hello-world
[sudo] password for vskumar:
IMAGE CREATED CREATED BY SIZE COMMENT
f2a91732366c 5 days ago /bin/sh -c #(nop) CMD [“/hello”] 0B
<missing> 5 days ago /bin/sh -c #(nop) COPY file:f3dac9d5b1b0307f… 1.85kB
vskumar@ubuntu:~$

======================>

Check the current docker information:

sudo docker info |more

======================================>

vskumar@ubuntu:~$ sudo docker info |more
Containers: 2
Running: 1
Paused: 0
Stopped: 1
Images: 6
Server Version: 17.11.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 14
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 992280e8e265f491f7a624ab82f3e238be086e49
runc version: 0351df1c5a66838d0c392b4ac4cf9450de844e2d
–More–WARNING: No swap limit support
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.10.0-40-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.933GiB
Name: ubuntu
ID: KH7E:PWA2:EJGE:MZCA:3RVJ:LU2W:BA7S:DTIQ:32HP:XXO7:RXBR:4XQI
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

vskumar@ubuntu:~$

=============================>

Now, let us work on the Docker images operations:

In the previous session, we demonstrated the typical Hello World example using the
hello-world image.

you can run an Ubuntu container with:

$ sudo docker run -it ubuntu bash

you can run an Ubuntu container with:

======= We are in Docker container =====>

vskumar@ubuntu:~$ sudo docker run -it ubuntu bash
root@10ffea6140f9:/#

============>

Now, let us apply some Linux commands as below:

==================>

root@10ffea6140f9:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@10ffea6140f9:/# ps -a
PID TTY TIME CMD
11 pts/0 00:00:00 ps
root@10ffea6140f9:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 05:36 pts/0 00:00:00 bash
root 12 1 0 05:38 pts/0 00:00:00 ps -ef
root@10ffea6140f9:/# cd lib
root@10ffea6140f9:/lib# ls
init lsb systemd terminfo udev x86_64-linux-gnu
root@10ffea6140f9:/lib# cd ..
root@10ffea6140f9:/# cd var
root@10ffea6140f9:/var# pwd
/var
root@10ffea6140f9:/var# ls
backups cache lib local lock log mail opt run spool tmp
root@10ffea6140f9:/var# cd log
root@10ffea6140f9:/var/log# ls
alternatives.log bootstrap.log dmesg faillog lastlog
apt btmp dpkg.log fsck wtmp

root@10ffea6140f9:/var/log# cat dpkg.log |more
2017-11-14 13:48:30 startup archives install
2017-11-14 13:48:30 install base-passwd:amd64 <none> 3.5.39
2017-11-14 13:48:30 status half-installed base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status unpacked base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status unpacked base-passwd:amd64 3.5.39
2017-11-14 13:48:30 configure base-passwd:amd64 3.5.39 3.5.39
2017-11-14 13:48:30 status unpacked base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status half-configured base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status installed base-passwd:amd64 3.5.39
2017-11-14 13:48:30 startup archives install
2017-11-14 13:48:30 install base-files:amd64 <none> 9.4ubuntu4
2017-11-14 13:48:30 status half-installed base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 configure base-files:amd64 9.4ubuntu4 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4

root@10ffea6140f9:/var/log#

==================================>

WE have seen this container like a Linux machine only.

Now, to come out into Docker use ‘exit’ command.

====================>

root@10ffea6140f9:/var/log#
root@10ffea6140f9:/var/log# exit
exit
vskumar@ubuntu:~$

vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-exercise/ubuntu-wgetinstall latest e34304119838 4 hours ago 169MB
<none> <none> fc7e4564eb92 4 hours ago 169MB
hello-world latest f2a91732366c 5 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 8 days ago 123MB
ubuntu latest 20c44cd7596f 8 days ago 123MB
busybox latest 6ad733544a63 3 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$

======================>

It means earlier when we run the command ‘$ sudo docker run -it ubuntu bash’ it went into terminal interactive mode of unbuntu container. When we applied ‘exit’ it came out from that container to ‘docker’ . Now through docker we have seen the list of docker images.

So, we have seen from the above session the container usage and the docker images.

Now, let us check the docker services status as below:

$sudo services docker status

vskumar@ubuntu:/var/tmp$ sudo service docker status

================================>

docker.service – Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e

Active: active (running) since Sat 2017-11-25 02:07:54 PST; 25min ago

Docs: https://docs.docker.com

Main PID: 1224 (dockerd)

Tasks: 18

Memory: 255.2M

CPU: 35.334s

CGroup: /system.slice/docker.service

├─1224 /usr/bin/dockerd -H fd://

└─1415 docker-containerd –config /var/run/docker/containerd/containe

================================>

Now, we will stop this session at this point in the next block we will learn how to download public docker image and work with images and containers.

Vcard-Shanthi Kumar V-v3

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s