Swetha – Docker Lab Assignment
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Install Docker Engine in Centos#1 Vm.
[centos@ip-172-31-7-48 ~]$ sudo systemctl start docker
[centos@ip-172-31-7-48 ~]$ history
1 sudo -s
2 exit
3 clear
4 ls
5 sudo yum install -y yum-utils device-mapper-persistent-data lvm2
6 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
7 sudo yum install –y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
8 sudo yum-config-manager --enable rhui-REGION-rhel-server-extras
9 sudo yum install -y docker-ce
10 docker -v
11 sudo systemctl enable docker
12 sudo systemctl start docker
13 history
Verify docker installation
[centos@ip-172-31-7-48 ~]$ which docker
/usr/bin/docker
[centos@ip-172-31-7-48 ~]$ which dockerd
/usr/bin/dockerd
[centos@ip-172-31-7-48 ~]$ which containerd
/usr/bin/containerd
[centos@ip-172-31-7-48 ~]$ ps -eaf|grep dockerd
root 10764 1 0 05:16 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
centos 10920 1458 0 05:26 pts/0 00:00:00 grep --color=auto dockerd
[centos@ip-172-31-7-48 ~]$ ps -eaf|grep containerd
root 10753 1 0 05:16 ? 00:00:00 /usr/bin/containerd
root 10764 1 0 05:16 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
centos 10922 1458 0 05:26 pts/0 00:00:00 grep --color=auto containerd
[centos@ip-172-31-7-48 ~]$ docker -v
Docker version 20.10.7, build f0df350
[centos@ip-172-31-7-48 ~]$
Assignment#1
Create Ubuntu Container
[centos@ip-172-31-7-48 ~]$ sudo -s
[root@ip-172-31-7-48 centos]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
a31c7b29f4ad: Pull complete
Digest: sha256:b3e2e47d016c08b3396b5ebe06ab0b711c34e7f37b98c9d37abe794b71cea0a2
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
[root@ip-172-31-7-48 centos]# docker run -itd ubuntu
49a0ac7cce4a06ca475f26e8e8c27a4b564346cff412e22c394308d7a5397d74
[root@ip-172-31-7-48 centos]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
49a0ac7cce4a ubuntu "bash" 6 seconds ago Up 5 seconds loving_goldwasser
Attaching to the container and Install Update, git & apache2 in ubuntu container
[root@ip-172-31-7-48 centos]# docker attach 49a0ac7cce4a
root@49a0ac7cce4a:/# yum install git
bash: yum: command not found
root@49a0ac7cce4a:/# apt-get update
root@49a0ac7cce4a:/# apt-get install apache2
root@49a0ac7cce4a:/# git --version
git version 2.25.1
Run git command in container from outside
ctrl+p+q - to come out from container
[root@ip-172-31-7-48 centos]# docker exec 49a0ac7cce4a git --version
git version 2.25.1
Assignment#2
Create a httpd container exposed at 8080 port
[root@ip-172-31-7-48 centos]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
[root@ip-172-31-7-48 centos]# docker container run --name web -d -p 8080:80 httpd
3ec7d0b852ee41f4f1fe30ee075b79bdfadf9c4090adcd6945d2411ac5b771c2
[root@ip-172-31-7-48 centos]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3ec7d0b852ee httpd "httpd-foreground" 6 seconds ago Up 5 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp web
Access(curl) container from node
[root@ip-172-31-7-48 centos]# curl localhost:8080
<html><body><h1>It works!</h1></body></html>
[root@ip-172-31-7-48 centos]# curl localhost:8081
curl: (7) Failed connect to localhost:8081; Connection refused
[root@ip-172-31-7-48 centos]# curl localhost:8080
<html><body><h1>It works!</h1></body></html>
Assignment#3
Create an image with base – centos and git must be installed in it
[root@ip-172-31-7-48 centos]# touch dockerfile
[root@ip-172-31-7-48 centos]# vi dockerfile
[root@ip-172-31-7-48 centos]# cat dockerfile
FROM ubuntu
MAINTAINER Swetha
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get -y install tzdata
RUN apt-get update && apt-get install git -y && apt-get install -yq apache2
CMD /usr/sbin/apache2ctl -D FOREGROUND
[root@ip-172-31-7-48 centos]# docker build -t ub-up-git .
[root@ip-172-31-7-48 centos]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ub-up-git latest c226f4a2cae2 7 minutes ago 259MB
ubuntu latest c29284518f49 7 days ago 72.8MB
Push a docker image to hub.docker.com
[root@ip-172-31-7-48 centos]# docker tag ub-up-git swetha97/test21
[root@ip-172-31-7-48 centos]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
swetha97/test21 latest c226f4a2cae2 16 minutes ago 259MB
ub-up-git-by-dockerfile latest c226f4a2cae2 16 minutes ago 259MB
ub-up-git latest c226f4a2cae2 16 minutes ago 259MB
ubuntu latest c29284518f49 7 days ago 72.8MB
[root@ip-172-31-7-48 centos]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: swetha97
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@ip-172-31-7-48 centos]# docker push swetha97/test21
https://hub.docker.com/r/swetha97/test21/tags?page=1&ordering=last_updated