KODEKLOUD ENGINEER GIT TASKS
The Nautilus development team started with new project development. They
have created different Git repositories to manage respective project's source
code. One of the repositories /opt/apps.git was created recently. The team has
given us a sample index.html file that is currently present on jump host under
/tmp directory. The repository has been cloned at /usr/src/kodekloudrepos on
storage server in Stratos DC. Copy sample index.html file from jump host to
storage server under cloned repository at /usr/src/kodekloudrepos/apps, further
add/commit the file and push to the master branch
ANSWER
Step 1: Copy the sample index.html file from the jump host to the storage server.
Assuming the jump host IP address is "JUMP_HOST_IP" and you have SSH access to it, and the
storage server IP address is "STORAGE_SERVER_IP":
# On your local machine, use the scp command to copy the index.html file from jump host to the
storage server
scp /tmp/index.html user@STORAGE_SERVER_IP:/tmp/
Make sure to replace "user" with your actual username on the storage server and provide the
appropriate password or SSH key if prompted.
Step 2: SSH into the storage server.
ssh user@STORAGE_SERVER_IP
Step 3: Move the index.html file to the appropriate location within the repository.
mv /tmp/index.html /usr/src/kodekloudrepos/apps
Step 4: Navigate to the repository on the storage server.
cd /usr/src/kodekloudrepos/apps
Step 5: Add, commit, and push the file to the master branch.
git add index.html
git commit -m "Add sample index.html"
git push origin master
The Nautilus application development team has been working on a project
repository /opt/apps.git. This repo is cloned
at /usr/src/kodekloudrepos on storage server in Stratos DC.
They recently shared the following requirements with DevOps team:
Create a new branch devops in /usr/src/kodekloudrepos/apps repo
from master and copy the /tmp/index.html file (present on storage
server itself) into the repo. Further, add/commit this file in the new branch and merge
back that branch into master branch. Finally, push the changes to the origin for both of
the branches.
ssh natasha@172.16.238.15
sudo git checkout -b devops master
cp /tmp/index.html /usr/src/kodekloudrepos/app
git add index.html
git commit -m "Add index.html to devops branch"
git merge devops
git push origin devops
git push origin master
The xFusionCorp development team added updates to the project that is
maintained under /opt/news.git repo and cloned
under /usr/src/kodekloudrepos/news. Recently some changes were
made on Git server that is hosted on Storage server in Stratos DC. The
DevOps team added some new Git remotes, so we need to update remote
on /usr/src/kodekloudrepos/news repository as per details mentioned
below:
a. In /usr/src/kodekloudrepos/news repo add a new remote dev_news and point
it to /opt/xfusioncorp_news.git repository.
b. There is a file /tmp/index.html on same server; copy this file to the repo and
add/commit to master branch.
c. Finally push master branch to this new remote origin.
1. Switch to the directory where the news repository is cloned:
cd /usr/src/kodekloudrepos/news
2. Add a new remote named dev_news and point it to
the /opt/xfusioncorp_news.git repository:
git remote add dev_news /opt/xfusioncorp_news.git
3. Copy the /tmp/index.html file to the repository:
cp /tmp/index.html .
4. Add and commit the index.html file:
git add index.html
git commit -m "Add index.html file"
5. Push the master branch to the dev_news remote:
git push dev_news master
The Nautilus application development team was working on a git
repository /usr/src/kodekloudrepos/official present on Storage
server in Stratos DC. However, they reported an issue with the recent
commits being pushed to this repo. They have asked the DevOps team to
revert repo HEAD to last commit. Below are more details about the task:
1. In /usr/src/kodekloudrepos/official git repository, revert the latest
commit ( HEAD ) to the previous commit (JFYI the previous commit hash
should be with initial commit message ).
2. Use revert official message (please use all small letters for commit
message) for the new revert commit.
Cd to the Repo
git log -1 (to see the last commit)
git revert -n <previous_commit_hash>
git commit -m "commit message"
git push origin master
GIT CHERRY PICK
The Nautilus application development team has been working on a project
repository /opt/apps.git. This repo is cloned
at /usr/src/kodekloudrepos on storage server in Stratos DC.
They recently shared the following requirements with the DevOps team:
There are two branches in this repository, master and feature. One of the developers
is working on the feature branch and their work is still in progress, however they want
to merge one of the commits from the feature branch to the master branch, the
message for the commit that needs to be merged into master is Update info.txt.
Accomplish this task for them, also remember to push your changes eventually.
cd kodekloudrepos/
19 cd apps/
23 git checkout master
29 git log feature --oneline
30 git cherry-pick 0390bbd
31 git push origin master
32 git checkout feature
33 ls
34 git log --oneline
In Git, git cherry-pick is a command that allows you to apply a specific commit from one branch to
another. This is useful for scenarios where you want to merge only the changes of some specific
commits into another branch (other than the branch where the commits reside).
For example, let's say you have a branch called master and a branch called feature. You've made
some changes to the feature branch that you want to merge into the master branch, but you only
want to merge the changes from the commit with the message "add new feature". You can use git
cherry-pick to do this.
@@MANAGE PULL RQUESTS@@
Max want to push some new changes to one of the repositories but we don't
want people to push directly to master branch, since that would be the final
version of the code. It should always only have content that has been
reviewed and approved. We cannot just allow everyone to directly push to the
master branch. So, let's do it the right way as discussed below:
SSH into storage server using user max, password Max_pass123 . There you can
find an already cloned repo under Max user's home.
Max has written his story about The 🦊 Fox and Grapes 🍇
Max has already pushed his story to remote git repository hosted
on Gitea branch story/fox-and-grapes
Check the contents of the cloned repository. Confirm that you can see Sarah's story and
history of commits by running git log and validate author info, commit message etc.
Max has pushed his story, but his story is still not in the master branch. Let's create a
Pull Request(PR) to merge Max's story/fox-and-grapes branch into
the master branch
Click on the Gitea UI button on the top bar. You should be able to access
the Gitea page.
UI login info:
- Username: max
- Password: Max_pass123
PR title : Added fox-and-grapes story
PR pull from branch: story/fox-and-grapes (source)
PR merge into branch: master (destination)
Before we can add our story to the master branch, it has to be reviewed. So, let's
ask tom to review our PR by assigning him as a reviewer
Add tom as reviewer through the Git Portal UI
Go to the newly created PR
Click on Reviewers on the right
Add tom as a reviewer to the PR
Now let's review and approve the PR as user Tom
Login to the portal with the user tom
Logout of Git Portal UI if logged in as max
UI login info:
- Username: tom
- Password: Tom_pass123
PR title : Added fox-and-grapes story
Review and merge it.
Great stuff!! The story has been merged!
Follow the given steps to create a pull request and review and merge the pull request in the master
branch
@@GIT HARD RESET@@
The Nautilus application development team was working on a git
repository /usr/src/kodekloudrepos/demo present on Storage
server in Stratos DC. This was just a test repository and one of the
developers just pushed a couple of changes for testing, but now they want to
clean this repository along with the commit history/work tree, so they want to
point back the HEAD and the branch itself to a commit with message add
data.txt file. Find below more details:
1. In /usr/src/kodekloudrepos/demo git repository, reset the git commit
history so that there are only two commits in the commit history i.e initial
commit and add data.txt file.
2. Also make sure to push your changes.
cd /usr/src/kodekloudrepos/demo
git log --oneline
git reset --hard <commit-hash>
git push origin HEAD –force
git push origin main
@@ Git Clean @@
git clean -f
@@ Git Stash @@
The Nautilus application development team was working on a git
repository /usr/src/kodekloudrepos/demo present on Storage
server in Stratos DC. One of the developers stashed some in-progress
changes in this repository, but now they want to restore some of the stashed
changes. Find below more details to accomplish this task:
Look for the stashed changes under /usr/src/kodekloudrepos/demo git
repository, and restore the stash with stash@{1} identifier. Further, commit and push
your changes to the origin.
Navigate to the Repository Directory:
cd /usr/src/kodekloudrepos/demo
To see a list of available stashes, use the following command:
git stash list
Restore the Stash:
git stash apply stash@{1}
If you want to remove the stash after applying it, you can use git stash pop instead of git stash apply.
git add .
git commit -m "Restored stashed changes"
git push origin master
@@ GIT REBASE @@
The Nautilus application development team has been working on a project
repository /opt/demo.git. This repo is cloned
at /usr/src/kodekloudrepos on storage server in Stratos DC.
They recently shared the following requirements with DevOps team:
One of the developers is working on feature branch and their work is still in progress,
however there are some changes which have been pushed into the master branch, the
developer now wants to rebase the feature branch with the master branch without
loosing any data from the feature branch, also they don't want to add any merge
commit by simply merging the master branch into the feature branch. Accomplish
this task as per requirements mentioned.
Also remember to push your changes once done.
git checkout feature
cd /usr/src/kodekloudrepos/demo
git fetch origin master
git rebase origin/master
git push origin feature –force (Force should be used wit caution as it might delete other’s updates),
you might need to resolve conflict if you are unable to push changes to remote
@@ Manage Git Repositories@@
A new developer just joined the Nautilus development team and has been
assigned a new project for which he needs to create a new repository under
his account on Gitea server. Additionally, there is some existing data that
need to be added to the repo. Below you can find more details about the task:
Click on the Gitea UI button on the top bar. You should be able to access
the Gitea UI. Login to Gitea server using username max and
password Max_pass123.
a. Create a new git repository story_media under max user.
b. SSH into storage server using user max and password Max_pass123 and clone
this newly created repository under user max home directory i.e /home/max.
c. Copy all files from location /usr/sysops to the repository and commit/push your
changes to the master branch. The commit message must be "add stories" (must
be done in single commit).
d. Create a new branch max_demo from master.
e. Copy a file story-index-max.txt from location /tmp/stories/ to the
repository. This file has a typo, which you can fix by changing the
word Mooose to Mouse. Commit and push the changes to the newly created branch.
Commit message must be "typo fixed for Mooose" (must be done in single
commit).
Note: For these kind of scenarios requiring changes to be done in a web UI, please
take screenshots so that you can share it with us for review in case your task is marked
incomplete. You may also consider using a screen recording software such as loom.com
to record and share your work.
ssh max@storage_server_ip
cd /home/max
git clone https://gitea_server_url/max/story_media.git
cd /usr/sysops
cp -r * /home/max/story_media/
cd /home/max/story_media
git add .
git commit -m "add stories"
git push origin master
git checkout -b max_demo
cp /tmp/stories/story-index-max.txt /home/max/story_media/
edited file with mouse instead mooose
git add story-index-max.txt
git commit -m "typo fixed for Mooose"
git push origin max_demo
@@ Git Hook @@
The Nautilus application development team was working on a git
repository /opt/news.git which is cloned
under /usr/src/kodekloudrepos directory present on Storage
server in Stratos DC. The team want to setup a hook on this repository,
please find below more details:
Merge the feature branch into the master branch`, but before pushing your
changes complete below point.
Create a post-update hook in this git repository so that whenever any
changes are pushed to the master branch, it creates a release tag with
name release-2023-06-15, where 2023-06-15 is supposed to be the
current date. For example if today is 20th June, 2023 then the release tag
must be release-2023-06-20. Make sure you test the hook at least once
and create a release tag for today's release.
Finally remember to push your changes.
Cd to bare repo
/opt/cluster.git/hooks
Then create the post-update hook
#!/bin/bash
# Get the current date
date=$(date +"%Y-%m-%d")
# Create a release tag with the current date
git tag release-$date
Once the tag is created go to cloned repo
Git checkout master
Git merge feature
You will see the tag has been release with current date.
@@GIT setup from scratch@@
Some new developers have joined xFusionCorp Industries and have
been assigned Nautilus project. They are going to start development on a
new application, and some pre-requisites have been shared with the DevOps
team to proceed with. Please note that all tasks need to be performed
on storage server in Stratos DC.
a. Install git, set up any values for user.email and user.name globally and create a bare
repository /opt/demo.git.
b. There is an update hook (to block direct pushes to the master branch)
under /tmp on storage server itself; use the same to block direct pushes to
the master branch in /opt/demo.git repo.
c. Clone /opt/demo.git repo in /usr/src/kodekloudrepos/demo directory.
d. Create a new branch named xfusioncorp_demo in repo that you cloned
under /usr/src/kodekloudrepos directory.
e. There is a readme.md file in /tmp directory on storage server itself; copy that to
the repo, add/commit in the new branch you just created, and finally push your branch
to the origin.
f. Also create master branch from your branch and remember you should not be able to
push to the master directly as per the hook you have set up.
On Storage server
Yum update -y
Yum install git -y
# Set user email and name globally
git config --global user.email "your.email@example.com"
git config --global user.name "Your Name"
# Create a bare repository
sudo mkdir /opt/blog.git
cd /opt/blog.git
sudo git init --bare
b. Set up Update Hook:
Assuming the update hook script is located at /tmp/update-hook.sh, you can set up the
update hook as follows:
# Copy the update hook script
sudo cp /tmp/update-hook.sh /opt/blog.git/hooks/update
sudo chmod +x /opt/blog.git/hooks/update
Make sure the contents of /tmp/update-hook.sh script block direct pushes to the master
branch.
c. Clone Repository:
# Clone the repository
sudo mkdir -p /usr/src/kodekloudrepos
cd /usr/src/kodekloudrepos
sudo git clone /opt/blog.git blog
d. Create a New Branch:
# Create a new branch
cd /usr/src/kodekloudrepos/blog
sudo git checkout -b xfusioncorp_blog
e. Copy and Commit Files:
Assuming readme.md is in /tmp:
# Copy the readme.md file and commit
sudo cp /tmp/readme.md /usr/src/kodekloudrepos/blog
cd /usr/src/kodekloudrepos/blog
sudo git add .
sudo git commit -m "Add readme.md to xfusioncorp_blog branch"
f. Create Master Branch:
# Create the master branch from your branch
sudo git checkout -b master xfusioncorp_blog
KODEKLOUD ENGINEER DOCKER TASKS
@@Run container@@
Nautilus DevOps team is testing some applications deployment on some of
the application servers. They need to deploy a nginx container
on Application Server 3. Please complete the task as per details given
below:
1. On Application Server 3 create a container named nginx_3 using
image nginx with alpine tag and make sure container is in running state.
Ssh to server 3
Check if docker is installed or not
Docker –version
Docker run –name nginx_3 -d nginx:alpine
@@ delete container @@
One of the Nautilus project developers created a container on App Server
1. This container was created for testing only and now we need to delete it.
Accomplish this task as per details given below:
Delete a container named kke-container, its running on App Server 1 in Stratos
DC.
Ssh into server 1
Checked for running container
If the container is running stop the container 1st and then delete
Docker stop <container_ID>
Docker rm <Container_ID>
Docker ps -a – to check if the container is removed or not
@@ Docker Copy @@
The Nautilus DevOps team has some confidential data present on App
Server 3 in Stratos Datacenter. There is a
container ubuntu_latest running on the same server. We received a
request to copy some of the data from the docker host to the container. Below
are more details about the task:
On App Server 3 in Stratos Datacenter copy an encrypted
file /tmp/nautilus.txt.gpg from docker host to ubuntu_latest container
(running on same server) in /opt/ location. Please do not try to modify this file in any
way.
docker cp /tmp/nautilus.txt.gpg ubuntu_latest:/opt/
docker exec -it ubuntu_latest bash
ls /opt/
exit
There is a static website running within a container named nautilus, this
container is running on App Server 1. Suddenly, we started facing some
issues with the static website on App Server 1. Look into the issue to fix the
same, you can find more details below:
1. Container's volume /usr/local/apache2/htdocs is mapped with the
host's volume /var/www/html.
2. The website should run on host port 8080 on App Server 1 i.e
command curl http://localhost:8080/ should work on App Server
1.
Checked for docker logs
Docker logs <container id>
Upon checking saw that container is not running, so started the container
Docker start <container id>
@@docker pull and tag@@
Nautilus project developers are planning to start testing on a new project. As
per their meeting with the DevOps team, they want to test containerized
environment application features. As per details shared with DevOps team, we
need to accomplish the following task:
a. Pull busybox:musl image on App Server 2 in Stratos DC and re-tag (create new
tag) this image as busybox:local.
1st pull docker image
Docker pull busybox:musl
Retag the pulled image
Docker tag busybox:musl busybox:local
@@run docker command without sudo@@
Check if the docker group is there or not (mostly docker creates this group)
getent group docker
add user to docker group if not present
sudo usermod -aG docker $USER
exit and login
test by using
docker –version
@@create docker image@@
One of the Nautilus developer was working to test new changes on a
container. He wants to keep a backup of his changes to the container. A new
request has been raised for the DevOps team to create a new image from this
container. Below are more details about it:
a. Create an image cluster:datacenter on Application Server 1 from a
container ubuntu_latest that is running on same server.
docker commit <container_id> cluster:datacenter
container is already created in above scenario
@@ Docker EXEC command @@
One of the Nautilus DevOps team members was working to configure services
on a kkloud container that is running on App Server 1 in Stratos
Datacenter. Due to some personal work he is on PTO for the rest of the
week, but we need to finish his pending work ASAP. Please complete the
remaining work as per details given below:
a. Install apache2 in kkloud container using apt that is running on App Server
1 in Stratos Datacenter.
b. Configure Apache to listen on port 3002 instead of default http port. Do not bind it to
listen on specific IP or hostname only, i.e it should listen on localhost, 127.0.0.1,
container ip, etc.
c. Make sure Apache service is up and running inside the container. Keep the container
in running state at the end.
ssh username@app-server-1-ip
docker exec -it kkloud_container_id bash
apt update
apt install apache2
nano /etc/apache2/ports.conf
nano /etc/apache2/apache2.conf
ServerName 127.0.0.1
systemctl status apache2
systemctl start apache2
systemctl enable apache2
if systemctl is not working
service apache2 restart
@@write a dockerfile@@
As per recent requirements shared by the Nautilus application development
team, they need custom images created for one of their projects. Several of
the initial testing requirements are already been shared with DevOps team.
Therefore, create a docker file /opt/docker/Dockerfile (please
keep D capital of Dockerfile) on App server 1 in Stratos DC and
configure to build an image with the following requirements:
a. Use ubuntu as the base image.
b. Install apache2 and configure it to work on 6400 port. (do not update any other
Apache configuration settings like document root etc).
dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y apache2
RUN sed -i 's/80/6400/g' /etc/apache2/ports.conf
EXPOSE 6400
CMD ["apache2ctl", "-D", "FOREGROUND"]
Save the dockerfile
sudo docker build -t my_custom_apache_image .
@@ Create Docker Network@@
The Nautilus DevOps team needs to set up several docker environments for
different applications. One of the team members has been assigned a ticket
where he has been asked to create some docker networks to be used later.
Complete the task based on the following ticket description:
a. Create a docker network named as blog on App Server 1 in Stratos DC.
b. Configure it to use macvlan drivers.
c. Set it to use subnet 172.168.0.0/24 and iprange 172.168.0.1/24.
docker network create -d macvlan --subnet=172.168.0.0/24 --ip-range=172.168.0.1/24 -o
parent=eth0 blog
@@ docker volume mapping @@
The Nautilus DevOps team is testing applications containerization, which
issupposed to be migrated on docker container-based environments soon. In
today's stand-up meeting one of the team members has been assigned a task
to create and test a docker container with certain requirements. Below are
more details:
a. On App Server 1 in Stratos DC pull nginx image (preferably latest tag but
others should work too).
b. Create a new container with name demo from the image you just pulled.
c. Map the host volume /opt/itadmin with container volume /tmp. There is
an sample.txt file present on same server under /tmp; copy that file
to /opt/itadmin. Also please keep the container in running state.
docker pull nginx:latest
docker run -d --name demo -v /opt/itadmin:/tmp nginx:latest
cp /tmp/sample.txt demo:/opt/itadmin
@@Docker Ports Mapping@@
The Nautilus DevOps team is planning to host an application on a nginx-based
container. There are number of tickets already been created for similar tasks. One of the
tickets has been assigned to set up a nginx container on Application Server 3 in Stratos
Datacenter. Please perform the task as per details mentioned below:
a. Pull nginx:alpine-perl docker image on Application Server 3.
b. Create a container named apps using the image you pulled.
c. Map host port 8088 to container port 80. Please keep the container in running state.
docker pull nginx:alpine-perl
docker run --name apps -p 8088:80 nginx:alpine-perl
@@Save, Load and Transfer Docker Image@@
One of the DevOps team members was working on to create a new custom
docker image on App Server 1 in Stratos DC. He is done with his
changes and image is saved on same server with
name ecommerce:xfusion. Recently a requirement has been raised by a
team to use that image for testing, but the team wants to test the same on App
Server 3. So we need to provide them that image on App Server
3 in Stratos DC.
a. On App Server 1 save the image ecommerce:xfusion in an archive.
b. Transfer the image archive to App Server 3.
c. Load that image archive on App Server 3 with same name and tag which was used
on App Server 1.
Note: Docker is already installed on both servers; however, if its service is down please
docker save -o ecommerce_xfusion.tar ecommerce:xfusion
scp ecommerce_xfusion.tar banner@172.16.238.12:.
ssh banner@172.16.238.12
Check Docker Status:
Open a terminal on the server and run the following command to check the status of the
Docker service:
sudo systemctl status docker
If Docker is running, you will see output indicating that the service is active and running.
Start Docker:
sudo systemctl start docker
This will start the Docker service. You can then check its status again using the status
command mentioned above.
Enable Docker on Startup:
To ensure Docker starts automatically on system boot, enable it with the following
command:
sudo systemctl enable docker
Check Docker Version:
docker –version
@@Write a Docker Compose File@@
The Nautilus application development team shared static website content that
needs to be hosted on the httpd web server using a containerised platform.
The team has shared details with the DevOps team, and we need to set up an
environment according to those guidelines. Below are the details:
a. On App Server 2 in Stratos DC create a container named httpd using a docker
compose file /opt/docker/docker-compose.yml (please use the exact name for
file).
b. Use httpd (preferably latest tag) image for container and make sure container is
named as httpd; you can use any name for service.
c. Map 80 number port of container with port 8083 of docker host.
d. Map container's /usr/local/apache2/htdocs volume with /opt/dba volume of
docker host which is already there. (please do not modify any data within these
locations).
version: '3'
services:
yuppp:
image: httpd:latest
container_name: httpd
ports:
- "5001:80"
volumes:
- /opt/finance:/usr/local/apache2/htdocs
The Nautilus Application development team recently finished development of
one of the apps that they want to deploy on a containerized platform. The
Nautilus Application development and DevOps teams met to discuss some of
the basic pre-requisites and requirements to complete the deployment. The
team wants to test the deployment on one of the app servers before going live
and set up a complete containerized stack using a docker compose fie. Below
are the details of the task:
1. On App Server 3 in Stratos Datacenter create a docker compose
file /opt/data/docker-compose.yml (should be named exactly).
2. The compose should deploy two services (web and DB), and each service
should deploy a container as per details below:
For web service:
a. Container name must be php_blog.
b. Use image php with any apache tag. Check here for more details.
c. Map php_blog container's port 80 with host port 3000
d. Map php_blog container's /var/www/html volume with host
volume /var/www/html.
For DB service:
a. Container name must be mysql_blog.
b. Use image mariadb with any tag (preferably latest). Check here for more details.
c. Map mysql_blog container's port 3306 with host port 3306
d. Map mysql_blog container's /var/lib/mysql volume with host
volume /var/lib/mysql.
e. Set MYSQL_DATABASE=database_blog and use any custom user ( except root )
with some complex password for DB connections.
3. After running docker-compose up you can access the app with curl
command curl <server-ip or hostname>:3000/
For more details check here.
Ans
version: '3'
services:
php_blog:
container_name: php_blog
image: php:latest
ports:
- "3000:80"
volumes:
- /var/www/html:/var/www/html
command: php -S 0.0.0.0:80 -t /var/www/html
mysql_blog:
container_name: mysql_blog
image: mariadb:latest
ports:
- "3306:3306"
volumes:
- /var/lib/mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: database_blog
MYSQL_USER: custom_user
MYSQL_PASSWORD: 1234567@
MYSQL_ROOT_PASSWORD: 1234567@
There is a requirement to Dockerize a Node app and to deploy the same
on App Server 2. Under /node_app directory on App Server 2, we
have already placed a package.json file that describes the app
dependencies and server.js file that defines a web app framework.
1. Create a Dockerfile (name is case sensitive) under /node_app directory:
o Use any node image as the base image.
o Install the dependencies using package.json file.
o Use server.js in the CMD.
o Expose port 5000.
2. The build image should be named as nautilus/node-web-app.
3. Now run a container named nodeapp_nautilus using this image.
o Map the container port 5000 with the host port 8092.
. Once deployed, you can test the app using a curl command on App Server 2:
curl http://localhost:8092
FROM node:alpine
WORKDIR /node_app
COPY package.json .
RUN npm install
COPY . .
EXPOSE 5000
CMD node server.js
docker run -d -p 8092:5000 --name nodeapp_nautilus nautilus/node-web-app
curl http://172.16.238.11:8092
Python dockerized app
A python app needed to be Dockerized, and then it needs to be deployed
on App Server 2. We have already copied a requirements.txt file
(having the app dependencies) under /python_app/src/ directory on App
Server 2. Further complete this task as per details mentioned below:
1. Create a Dockerfile under /python_app directory:
o Use any python image as the base image.
o Install the dependencies using requirements.txt file.
o Expose the port 8088.
o Run the server.py script using CMD.
2. Build an image named nautilus/python-app using this Dockerfile.
3. Once image is built, create a container named pythonapp_nautilus:
o Map port 8088 of the container to the host port 8093.
4. Once deployed, you can test the app using curl command on App Server
2.
curl http://localhost:8093/
nano Dockerfile
FROM python:alpine
WORKDIR /python_app
COPY /src .
RUN pip install -r requirements.txt
EXPOSE 8088
CMD python server.py
docker build -t nautilus/python-app .
docker run -d -p 8093:8088 --name pythonapp_nautilus nautilus/python-app
curl http://172.16.238.11:8093