Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Docker Lab Guide

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

##########################

### Install Docker #####


##########################

#1. Instal Docker


sudo apt -y install docker.io
sudo systemctl status docker

#2. Menampilkan versi docker


sudo docker version

#3. Menampilkan detil instalasi docker


sudo docker info

#4. Uji instalasi docker


sudo docker run hello-world

#5. Menampilkan image yang sudah didownload


sudo docker image ls

#6. Menampilkan semua container (active ataupun exit)


sudo docker container ls -a

!!!!!! EKSEKUSI DI PODX-NODE0 !!!!!!

##########################
##### Operasional Docker ####
##########################

#1. Mengunduh image


sudo docker pull ubuntu:16.04

#2. Membuat container


sudo docker run -itd --name my-apps -p 8000:80 ubuntu:16.04

#3. Menampilkan metadata container


sudo docker container inspect my-apps

#4. Menghapus container


sudo docker container rm -f my-apps

#5. Menghapus image


sudo docker image rm ubuntu:16.04

##########################
######## Dockerfile ########
##########################

#1. Buat direktori latihan02


mkdir latihan02
cd latihan02

#2. Clone repository


git clone https://github.com/rivawahyuda/mywebsite.git
cd mywebsite

#3. Buat Dockerfile


vim Dockerfile
...
FROM ubuntu:latest
RUN apt update -y && apt install -y tzdata && apt install -y apache2
ADD . /var/www/html/
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
...

#4. Build image


sudo docker build -t myweb .

#5. Run image


sudo docker run -d -p 4000:80 myweb

#6. Uji browsing app


ssh root@lab1.btech.id -pXXXX -DYYYY
*Akses di browser IP_INTERNAL:4000

#########################
##### Publish Image #####
#########################

#1. Jika belum punya Docker ID, register di https://id.docker.com

#2. Login dengan Docker ID


sudo docker login

#3. Tag image


sudo docker tag myweb [USERNAME]/latihan:latihan02

#4. Tampilkan image yang sudah dibangun


sudo docker image ls

#5. Dorong image ke repo


sudo docker push [USERNAME]/latihan:latihan02

#6. Uji jalankan image


sudo docker run -itd --name web-latihan -p 4001:80 [USERNAME]/latihan:latihan02

#7. Tampilkan container Up


sudo docker container ls

#8. Uji browsing app


curl http://localhost:4000

#9. Stop container


sudo docker container stop [CONTAINER ID]

#10. Tampilkan container Up


sudo docker container ls -a

#########################
# Docker Compose Example #
#########################
#0 Install docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-
compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

#1 Ambil Berkas dari Github


git clone https://github.com/dockersamples/example-voting-app

#2 Masuk ke direktori
cd example-voting-app

#3 Jalankan docker-compose
sudo docker-compose -f docker-compose.yml up -d

#########################
# Docker Compose Example 2#
#########################

#1. Buat folder baru


mkdir docker-compose-lat-2
cd docker-compose-lat-2

#2. Buat folder untuk menyimpan index.html


mkdir web1
mkdir web2
mkdir web3

#3. buat file index. html


echo "Ini dari web1" > web1/index.html
echo "Ini dari web2" > web2/index.html
echo "Ini dari web3" > web3/index.html

#4. buat docker compose


vim docker-compose.yml

...

version: "3"

services:

web1:
image: httpd:latest
container_name: web1
ports:
- "5005:80"
volumes:
- ./web1:/usr/local/apache2/htdocs
network_mode: "bridge"

web2:
image: httpd:latest
container_name: web2
ports:
- "5006:80"
volumes:
- ./web2:/usr/local/apache2/htdocs
network_mode: "bridge"

web3:
image: httpd:latest
container_name: web3
ports:
- "5007:80"
volumes:
- ./web3:/usr/local/apache2/htdocs
network_mode: "bridge"

...

#5. Jalankan docker compose


sudo docker-compose -f docker-compose.yml up -d

###################
##### Volumes #####
###################

#1. Membuat volume


sudo docker volume create my-vol

#2. Menampilkan daftar volume


sudo docker volume ls

#3. Menampilkan detil volume


sudo docker volume inspect my-vol

#4. Jalankan container dengan volume


sudo docker run -d --name=nginxtest -v my-vol:/usr/share/nginx/html nginx:latest

#5. Tampilkan alamat IP container


sudo docker inspect nginxtest | grep -i ipaddress

#6. Uji browsing ke alamat IP container


curl http://172.17.XXX.XXX

#7. Buat file index.html dan pindahkan ke direktori source volume


sudo echo "This is from my-vol source directory" > index.html
sudo mv index.html /var/lib/docker/volumes/my-vol/_data/

#8. Uji browsing ke alamat IP container


curl http://172.17.XXX.XXX

#9. Jalankan container dengan read-only volume


sudo docker run -d --name=nginxtest-rovol -v my-vol:/usr/share/nginx/html:ro
nginx:latest

######################
##### Volume Driver #####
######################

#1. SSH ke podX-node1. Buat folder /share dan exit kembali (pastikan sudah bisa ssh
password less di podX-node1)
ssh -l root 10.X0.X0.11
sudo mkdir /share
sudo chmod 777 /share
exit

#2. Instal plugin sshfs


sudo docker plugin install --grant-all-permissions vieux/sshfs
sudo docker plugin ls
sudo docker plugin disable [PLUDIN ID]
sudo docker plugin set vieux/sshfs sshkey.source=/root/.ssh/
sudo docker plugin enable [PLUDIN ID]
sudo docker plugin ls

#3. Membuat volume dengan driver sshfs


sudo docker volume create --driver vieux/sshfs -o sshcmd=root@10.X.X.Y:/share -o
allow_other sshvolume

#4. Uji jalankan container dengan volume


sudo docker run -d --name=nginxtest-ssh -p 8090:80 -v
sshvolume:/usr/share/nginx/html nginx:latest

#5. Eksekusi di podX-node0


sudo docker container ls -a
curl http://localhost:8090

######################
##### Networking #####
######################

# Default Bridge Network #

#1. List network yang tersedia


Sudo docker network ls

#2. Create network bridge baru


Sudo docker network create -d bridge net-bridge1
Sudo docker network create -d bridge net-bridge2

#3. Buat 2 container ubuntu dengan network bridge yang berbeda


Sudo docker run -itd --name ubuntu1 --network net-bridge1 --hostname ubuntu1
ubuntu:18.04
Sudo docker run -itd --name ubuntu2 --network net-bridge2 --hostname ubuntu2
ubuntu:18.04

#4. Menampilkan informasi kontainer


Sudo docker container inspect ID_CONTAINER/NAMA_CONTAINER

#5. Masuk kedalam kontainer


Sudo docker exec -ti NAMA/ID_CONTAINER bash

#6. Test ping ( masuk ke ubuntu1 kemudian ping ip ubuntu2)


Sudo docker exec -ti ubuntu1 bash
Ping IP_ubuntu2

#7. Menambahkan menambahkan spesific network bridge


Sudo docker network connect net-bridge2 ubuntu1
#8. Test ping kembali, dari ubuntu1 ke ubuntu2

You might also like