Docker
In this section we will install docker, create images, build containers and much more. Let's Set SAIL!
To install Docker run the following commands:
Now we have installed and configured docker perfectly, we can run docker ps
command to see list of containers right now we do not have any containers. Lets build one container and install Tomcat server on it.
Create Docker Container
Before we go ahead and run customers lets learn few common docker commands
:
Now lets run our first docker command to pull Tomcat image from DOCKERHUB
Now we have Tomcat image ready let's build a container from this image and run it.
COMMANDS:
If you wish to delete docker container first stop the container by running docker stop <Container ID>
and delete by running docker rm <container id>
Npw if you run docker ps -a
, you will see the container is deleted. dokcer rmi <image ID>
to delete image
So we will copy contents of webapp.dist in webapp by running :
cp -r ./* /usr/local/tomcat/webapps
Now we have everything except the build file, But where is BUILD FILE?!! If you have been here from the start you might know that Jenkins from another server transferred our file to this server we are running our tomcat server. So we need to COPY build file from Host server >> Tomcat server>> webapps folder. Follow the steps:
Exit the container by typing exit in the terminal. Now you returned back to Server where we have docker installed with tomcat running on it.
run
sudo docker cp webapp.war tomcat:/usr/local/tomcat/webapps/webapp.war
And if you access
IP:8080/webapp/
you can see your website that you created and stored on Git.
Congratulations !! We have successfully deployed build file received by JENKINS server (through GITHUB code) on DOCKER >> Tomcat Server. I am so incredibly proud of you.
We did a lot of manual task like pulling image, building and runnning containers and copying war file from host to container but worry not we can automate all this hefty task by creating a DOCKERFILE in next section.
Last updated