Lab 4.2: Exploring Dockerfile - Part 2

Dockerfile (latihan03)

1. Buat direktori latihan03

cd $HOME
mkdir latihan03
cd latihan03

2. Clone repository

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

3. Buat Dockerfile. [screenshot-4-2-3]

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. [screenshot-4-2-6]

ssh root@labZ.btech.id -DYYYY

Akses di browser 10.X.X.10:4000

7. Tampilkan container Up. [screenshot-4-2-7]

sudo docker container ls -a

8. Stop container

sudo docker container stop [CONTAINER ID]

Dockerfile (latihan04)

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

2. Login dengan Docker ID

sudo docker login

3. Buat direktori latihan04

cd $HOME
mkdir latihan04
cd latihan04

4. Membuat file flask. [screenshot-4-2-4]

vim app.py
...
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hey, we have Flask in a Docker container!'


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')
...

5. Membuat requirements.txt. [screenshot-4-2-5]

echo "Flask==0.10.1" >> requirements.txt

6. Membuat file Dockerfilenya. [screenshot-4-2-6-2]

vim Dockerfile
...
FROM ubuntu:16.04
RUN mkdir /app
RUN apt-get update -y && \
        apt-get install python-pip python-dev -y

COPY ./requirements.txt /app
COPY . /app

WORKDIR /app
RUN pip install -r requirements.txt

ENTRYPOINT ["python"]
CMD ["app.py"]
...

7. Buat image dari Dockerfile

docker build -t flask-latihan04 .

8. Tag image

sudo docker tag flask-latihan04 [username]/flask-latihan04:latest

9. Push image

sudo docker push [username]/flask-latihan04:latest

10. Menjalankan image

sudo docker run -d -p 5000:5000 --name flask04 [username]/flask-latihan04

11 Uji browsing. [screenshot-4-2-11]

curl localhost:5000
Daftar Materi