Containerize Applications
Containerize Applications
0 documentation
The appropriate kubernetes related tools (docker, kubectl, kubernetes, etc.) have already been
installed ahead of me.
k8s-start
cd ~/
wget https://s3.eu-central-1.amazonaws.com/heptio-edu-static/how/gowebapp.tar.gz
cd $HOME/gowebapp/gowebapp
https://3i66gn3czc6mcuvtc-ae2dj6ktg38whmksx.rp.strigo.io/instructions/lab01/lab01.html 1/5
Create a file named
8/13/2019
in this directory for the frontend Go applica on. Use vi or any
Lab 01: Containerize Applications — Intro to Containers and Kubernetes 1.0.0 documentation
Dockerfile
Dockerfile-gowebapp
1 FROM ubuntu
2
3 COPY ./code /opt/gowebapp
4 COPY ./config /opt/gowebapp/config
5
6 EXPOSE 80
7
8 WORKDIR /opt/gowebapp/
9 ENTRYPOINT ["/opt/gowebapp/gowebapp"]
cd $HOME/gowebapp/gowebapp
Build the gowebapp image locally. Make sure to include “.“ at the end. Make sure the build runs
to comple on without errors. You should get a success message.
cd $HOME/gowebapp/gowebapp-mysql
Create a file named Dockerfile in this directory for the backend MySQL database. Use vi or any
preferred text editor. Populate it with the following code snippet.
Dockerfile-gowebapp-mysql
https://3i66gn3czc6mcuvtc-ae2dj6ktg38whmksx.rp.strigo.io/instructions/lab01/lab01.html 2/5
8/13/2019 Lab 01: Containerize Applications — Intro to Containers and Kubernetes 1.0.0 documentation
1 FROM mysql:5.6
2
3 COPY gowebapp.sql /docker-entrypoint-initdb.d/
cd $HOME/gowebapp/gowebapp-mysql
Build the gowebapp-mysql image locally. Make sure to include “.“ at the end. Make sure the build
runs to comple on without errors. You should get a success message.
To facilitate cross-container communica on, let’s first define a user-defined network in which to
run the frontend and backend containers:
Next, let’s launch a frontend and backend container using the Docker CLI.
sleep 20
docker run -p 9000:80 --net gowebapp -d --name gowebapp --hostname gowebapp gowebapp:v1
https://3i66gn3czc6mcuvtc-ae2dj6ktg38whmksx.rp.strigo.io/instructions/lab01/lab01.html 3/5
First, we launched the database
8/13/2019
container, as it will take a bit longer to startup, and the frontend
Lab 01: Containerize Applications — Intro to Containers and Kubernetes 1.0.0 documentation
container depends on it. No ce how we are injec ng the database password into the MySQL
configura on as an environment variable:
Next we paused for 20 seconds to give the database a chance to start and ini alize.
Finally we launched a frontend container, mapping the container port 80 - where the web
applica on is exposed - to port 9000 on the host machine:
Now that we’ve launched the applica on containers, let’s try to test the web applica on locally.
You should be able to access the applica on at h p://<EXTERNAL-IP>:9000.
Note
To get the EXTERNAL-IP of your host, run the command lab-info in your lab terminal
Create an account and login. Write something on your Notepad and save it. This will verify that
the applica on is working and properly integrates with the backend database container.
Let’s connect to the backend MySQL database container and run some queries to ensure that
applica on persistence is working properly:
Once connected, run some simple SQL commands to inspect the database tables and
persistence:
https://3i66gn3czc6mcuvtc-ae2dj6ktg38whmksx.rp.strigo.io/instructions/lab01/lab01.html 4/5
When we’re finished tes Lab
8/13/2019
ng,01:we can terminate and remove the currently running frontend and
Containerize Applications — Intro to Containers and Kubernetes 1.0.0 documentation
We are finished tes ng our images. We now need to push our images to an image registry so our
Kubernetes cluster can access them. First, we need to tag our Docker images to use the registry
in your lab environment:
Lab 01 Conclusion
Congratula ons! By containerizing your applica on components, you have taken the first
important step toward deploying your applica on to Kubernetes.
https://3i66gn3czc6mcuvtc-ae2dj6ktg38whmksx.rp.strigo.io/instructions/lab01/lab01.html 5/5