Dockerfile Instructions Contd…
- LABEL: This instruction adds metadata Refer Here
- Refer Here for the changes done for spc image
- Lets inspect the image
docker image inspect spc:1.0.0.1
and observe the labels section
ADD, COPY instructions
- ADD instruction can add the files into docker image from local file system as well as from http(s)
- ADD instruction can have sources
- local file system
- git repo
- url
- COPY supports only local file system
- Lets use ADD to download springpetclinic into docker image from url
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar /spring-petclinic-2.4.2.jar
- Refer Here for the changes
- copy the springpetclinic jar file into some local path on docker host. Refer Here for the changes done
What do we mean by running container in detached mode?
- Lets try to start the docker container jenkins
jenkins/jenkins
- docker container’s STDOUT and STDERR will be attached to your terminal and if we execute ctrl+c the container exits.
- Running container normally will take us to attached mode.
- In detached mode container executes and gives us back the access to terminal
- Once we start the container in detached mode we can still view the STDOUT and STDERR by executing
docker container attach <container-name-or-id>
- To exit from attach mode
Ctrl+PQ
Docker container will be in running state as long as command in cmd is running
- Consider the following Dockerfile
FROM amazoncorretto:11
LABEL author="shaikkhajaibrahim"
LABEL organization="qt"
LABEL project="learning"
# Copy from local file on Docker host into docker image
COPY spring-petclinic-2.4.2.jar /spring-petclinic-2.4.2.jar
EXPOSE 8080
CMD ["sleep", "10s"]
- We have sleep 10s i.e. this will run for 10s and finish.
- Docker container will move to exited stated once the command in CMD has finished executing
Exercise:
- Create a ubuntu vm
- install apache2 and note the ExecStart command for apache2
- install tomcat9 and note the ExecStart command for tomcat9
- stop the services (systemcl stop servicename)
- become a root user (sudo -i)
- try executing the ExecStart command directly and see if the application is running