Docker – Lab – Day1-3 – Sandeep

  1. Create Ec2 ubuntu instance (freeetire) in AWS
  2. Copy the permissions keys to local
  3. Open putty key load and generate private key
  4. Open Putty and browse the private key and login to the ubuntu instance
  5. Auto logged in with no credentials
  6. Install docker
  7. https://docs.docker.com/engine/install/ubuntu/
  8. sudo apt install apache2
  9. sudo apt-get install git
  10. Install Ansible:
    sudo apt-add-repository ppa:ansible/ansible

Log into the Ubuntu Server that will host Ansible

Install the necessary repository with the command sudo apt-add-repository ppa:ansible/ansible.

Update apt with the command sudo apt-get update.

Install Ansible with the command sudo apt-get install ansible -y.

ubuntu@ip-172-31-36-167:~$ docker -v
Docker version 20.10.6, build 370c289
ubuntu@ip-172-31-36-167:~$ which docker
/usr/bin/docker
ubuntu@ip-172-31-36-167:~$ which dockerd
/usr/bin/dockerd
ubuntu@ip-172-31-36-167:~$ which containerd
/usr/bin/containerd
sudo apt install apache2
ubuntu@ip-172-31-36-167:~$ sudo apt-get install git
Reading package lists… Done
Building dependency tree
Reading state information… Done
git is already the newest version (1:2.25.1-1ubuntu3.1).
0 upgraded, 0 newly installed, 0 to remove and 83 not upgraded.
 
git version 2.25.1
docker start d2284fa3b876
docker stop d2284fa3b876
docker start d2284fa3b876
docker restart d2284fa3b876
docker pause d2284fa3b876
docker unpause d2284fa3b876
docker kill d2284fa3b876
docker rm d2284fa3b876
Docker ps -a
Docker images
Df -kh
overlay         7.7G  2.8G  5.0G  36% /var/lib/docker/overlay2/aa0adb35162df4589704c14803ba465a45ab493dccaead7d3cbc3b827ebec578/merged
ubuntu@ip-172-31-36-167:~$ sudo docker run -it -d ubuntu
4a6368fbfdf3134efa6c1b53c399d7e0a786fa5197ef2a4986ca1f81d52a46b9
 
ubuntu@ip-172-31-36-167:~$ docker run -it ubuntu:latest /bin/bash
root@3495aa19c4ad:/#
 
ubuntu@ip-172-31-36-167:~$ docker run -itd ubuntu:latest /bin/bash
52405e2c22b4f9526bbfd3b598d92055d20a1030d13752c476494fb482e56009
 
 
 
ubuntu@ip-172-31-36-167:~$ docker start e220e9b0e897
ubuntu@ip-172-31-36-167:~$ docker attach e220e9b0e897 (ubuntu conatiner)
root@e220e9b0e897:/# pwd
/
root@e220e9b0e897:/# ls
bin  boot  dev  etc  home  lib  lib32  lib64  libx32  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
Exit (command) : pushes you out of container and stops the container
ctrl+pq (shortcut) : pushes you out of container and let the container continue running
 
 
 
ubuntu@ip-172-31-36-167:~$ mkdir dock-image
ubuntu@ip-172-31-36-167:~$ cd dock-image
ubuntu@ip-172-31-36-167:~/dock-image$ vi dockerfile
ubuntu@ip-172-31-36-167:~/dock-image$ touch index.html
ubuntu@ip-172-31-36-167:~/dock-image$ pwd
/home/ubuntu/dock-image
 
ubuntu@ip-172-31-36-167:~/dock-image$ docker build -t ub-up-git .
Sending build context to Docker daemon   2.56kB
Step 1/5 : FROM ubuntu
 —> c29284518f49
Step 2/5 : MAINTAINER Sandeep Draksharapu <thesdandy96@gmail.com>
 —> Running in ed426586cda4
Removing intermediate container ed426586cda4
 —> 6db668bbb9d4
Step 3/5 : RUN apt-get update
 —> Running in 63a946079b3a
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
ubuntu@ip-172-31-36-167:~/dock-image$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED          SIZE
ub-up-git     latest    a78f67cafcec   23 seconds ago   204MB
ubuntu@ip-172-31-36-167:~$ 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: thesandy96
Password:
WARNING! Your password will be stored unencrypted in /home/ubuntu/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
 
Login Succeeded
ubuntu@ip-172-31-36-167:~/dock-image$ docker tag ub-up-git thesandy96/dockerlab
ubuntu@ip-172-31-36-167:~/dock-image$ docker images
REPOSITORY             TAG       IMAGE ID       CREATED         SIZE
ub-up-git              latest    a78f67cafcec   2 minutes ago   204MB
thesandy96/dockerlab   latest    a78f67cafcec   2 minutes ago   204MB
 
ubuntu@ip-172-31-36-167:~/dock-image$ docker tag ub-up-git:latest thesandy96/dockerlab:myubuntuimage
ubuntu@ip-172-31-36-167:~/dock-image$ docker images
REPOSITORY             TAG             IMAGE ID       CREATED         SIZE
thesandy96/dockerlab   latest          a78f67cafcec   4 minutes ago   204MB
thesandy96/dockerlab   myubuntuimage   a78f67cafcec   4 minutes ago   204MB
ub-up-git              latest          a78f67cafcec   4 minutes ago   204MB
 
ubuntu@ip-172-31-36-167:~$ docker push thesandy96/dockerlab:myubuntuimage
The push refers to repository [docker.io/thesandy96/dockerlab]
77a90f426ac1: Pushed
181a340af0cd: Pushed
f51af2ec0c1f: Pushed
a70daca533d0: Mounted from library/ubuntu
ubuntu@ip-172-31-36-167:~$ docker rmi thesandy96/dockerlab
Untagged: thesandy96/dockerlab:latest
Docker rm 4a6368fbfdf3
 
ubuntu@ip-172-31-36-167:~$ docker images
REPOSITORY             TAG             IMAGE ID       CREATED          SIZE
ub-up-git              latest          8c689035cb0f   24 minutes ago   204MB
thesandy96/dockerlab   latest          8c689035cb0f   24 minutes ago   204MB
thesandy96/dockerlab   myubuntuimage   8c689035cb0f   24 minutes ago   204MB
 
ubuntu@ip-172-31-36-167:~$ docker exec 4a6368fbfdf3 ps -ef
UID          PID    PPID  C STIME TTY          TIME CMD
root           1       0  0 06:44 pts/0    00:00:00 bash
root          15       0  0 06:46 ?        00:00:00 ps -ef
 
ubuntu@ip-172-31-36-167:~$ docker exec 4a6368fbfdf3 df -kh
Filesystem      Size  Used Avail Use% Mounted on
overlay         7.7G  3.3G  4.4G  43% /
tmpfs            64M     0   64M   0% /dev
tmpfs           489M     0  489M   0% /sys/fs/cgroup
shm              64M     0   64M   0% /dev/shm
/dev/root       7.7G  3.3G  4.4G  43% /etc/hosts
tmpfs           489M     0  489M   0% /proc/acpi
tmpfs           489M     0  489M   0% /proc/scsi
tmpfs           489M     0  489M   0% /sys/firmware
 
ubuntu@ip-172-31-36-167:~$ docker exec -it 4a6368fbfdf3 /bin/bash
root@4a6368fbfdf3:/# pwd
/