Docker and Containers
For premium DevOps and AWS Courses: https://imojo.in/2cox7em
- AWS with the project
- DevOps Real-Time
- DevOps with the project
- AWS Real-Time
- Linux Admin
Installation
#yum update
#reboot
# curl -fsSL
https://get.docker.com/ | sh
After
installation start the docker
#systemctl start docker
#systemctl status docker
#docker version
Client:
Version:
17.03.1-ce
API version:
1.27
Go version:
go1.7.5
Git commit:
c6d412e
Built:
Fri Mar 24 00:36:45 2017
OS/Arch:
linux/amd64
Server:
Version:
17.03.1-ce
API version:
1.27 (minimum version 1.12)
Go version:
go1.7.5
Git commit:
c6d412e
Built:
Fri Mar 24 00:36:45 2017
OS/Arch:
linux/amd64
Experimental: false
#docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
……
……
To
check whether you can access and download images from Docker Hub, type:
# docker run hello-world
Unable
to find image 'hello-world:latest' locally
latest:
Pulling from library/hello-world
78445dd45222:
Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status:
Downloaded newer image for hello-world:latest
Hello
from Docker!
This
message shows that your installation appears to be working correctly.
…..
…….
Check
if any container is running
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
No
container is running.
With
below command we can see one container was running but it exited.
# docker ps -a
CONTAINER
ID IMAGE COMMAND CREATED STATUS PORTS NAMES
157130d8510e hello-world "/hello" 9 minutes ago Exited
(0) 9 minutes ago
admiring_beaver
# docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 48b5124b2768 2 months ago 1.84 kB
So
we have a image stored locally.
Theory of Pulling and Running containers:
Container and Images:
To pull a image. It will always pull the latest unless
version is specified.
# docker pull alpine
Using
default tag: latest
latest:
Pulling from library/alpine
627beaf3eaaf:
Pull complete
Digest: sha256:58e1a1bb75db1b5a24a462dd5e2915277ea06438c3f105138f97eb53149673c4
Status:
Downloaded newer image for alpine:latest
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 4a415e366388 3 weeks ago 3.98 MB
hello-world latest 48b5124b2768 2 months ago 1.84 kB
Note:
Login on docker website with the id and can check the images and their
vulnerabilities.
To
remove image from local repo.
# docker rmi alpine
Untagged: alpine:latest
Untagged:
alpine@sha256:58e1a1bb75db1b5a24a462dd5e2915277ea06438c3f105138f97eb53149673c4
Deleted:
sha256:4a415e3663882fbc554ee830889c68a33b3585503892cc718a4698e91ef2a526
Deleted: sha256:23b9c7b43573dd164619ad59e9d51eda4095926729f59d5f22803bcbe9ab24c2
Container Lifecycle:
Once
we create container by docker run command. We can stop it and start it, n number of times. We can also remove it.
Will
not loose data until container is topped and then removed.
#docker
start <container>
#docker
stop <container>
#docker
rm <container>
Download
ubuntu image:
# docker pull ubuntu
#docker images
ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
Even if we have not run the above step, below command will
download the image.
# docker run -it
ubuntu /bin/bash
# uname -a
Linux
df40e984506e 3.10.0-514.16.1.el7.x86_64 #1 SMP Wed Apr 12 15:04:24 UTC 2017
x86_64 x86_64 x86_64 GNU/Linux
Above means it is using underlying OS kernel.
# grep -i PRETTY_NAME
/etc/os-release
PRETTY_NAME="Ubuntu
16.04.2 LTS"
# apt-get update
Hit:1
http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:2
http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:3
http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4
http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading
package lists... Done
# yum check update
bash: yum: command not found
To
Stop all the running containers:
# docker stop $(docker ps
-aq)
31b5e12715ed
83c872994610
157130d8510e
Delete all the containers
# docker rm $(docker ps -aq)
31b5e12715ed
83c872994610
157130d8510e
Delete all the images:
# docker rmi $(docker images -q)
Click the link below to more : -