0% found this document useful (0 votes)
61 views3 pages

Docker File

The document provides a guide on creating Docker images using commands like 'docker commit' and creating Dockerfiles. It explains various Dockerfile instructions such as FROM, MAINTAINER, RUN, CMD, and ENTRYPOINT, along with examples. Additionally, it includes a sample Dockerfile and a script 'run.sh' demonstrating the use of environment variables and command execution within a container.

Uploaded by

bhanuece
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Docker File

The document provides a guide on creating Docker images using commands like 'docker commit' and creating Dockerfiles. It explains various Dockerfile instructions such as FROM, MAINTAINER, RUN, CMD, and ENTRYPOINT, along with examples. Additionally, it includes a sample Dockerfile and a script 'run.sh' demonstrating the use of environment variables and command execution within a container.

Uploaded by

bhanuece
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Creating Images

==============
1) Commit command
2) Dockerfile
3) Docker-compose
==================
1) docker run -it --name u1 ubuntu
/# apt-get update
/# apt-get install git -y
/# git --version
/# ctrl+pq
//creating image from container u1 with latest changes
$ docker commit -m "creating git image" u1 mynewimage:1.0
$ docker images
o/p: mynewimage:1.0
=============================
DOCKERFILE
===========
INSTRUCTION argument
====
FROM-> it will take base image
Ex: FROM ubuntu, FROM python, FROM centos, FROM tomcat...
==
MAINTAINER->it willtakae name and emailid
Ex: MAINTAINER bhanu<[email protected]>
===
RUN--> linux commands execute purpose
Ex:
RUN apt-get update
RUN apt-get install git -y
RUN apt-get install maven -y
==
RUN apt-get update \
&& apt-get install git -y \
&& apt-get install maven -y
===
LABEL
======
LABEL app=git
===
docker label -l cname...
====
CMD
====
CMD --it is used to execute commands when container create execution
EX:
CMD git --version
OR
CMD [ "git","--version" ] ( docker run -it newimage)
==
ENTRYPOINT
==========
it is used to execute commands when container create execution..
ex:
ENTRYPOINT git --version
ENTRYPOINT [ "git","--version" ] ( docker run -it newimage).
Ex: Entrypoint [dockerentrypoint.sh]
CMD vs ENtrypoint
================
CMD can override the command at run time.
docker run -it --name t1 newimage mvn --version
( mvn 2.4)
ENTRYPOINT cannot ovveride the command at run time.
docker run -it --name t1 newimage mvn --version
(git 2.7)
==
CMD & ENTRYPOINT
==================
ENTRYPOINT [ "git" ]
CMD ["--version"]
==============
WORKDIR
========
WORKDIR /dir1 - We can change the working directory
==
ENV
====
ENV JAVA_HOME=/usr/bin/java ( it will set environment variables)
==
ENTRYPOINT [./run.sh]
CMD ["arg1"]
# ./run.sh arg1

Dockerfile
=========
FROM ubuntu
MAINTAINER bhanu
RUN apt-get update \
&& apt-get install git -y \
&& apt-get install maven -y
CMD [ "--version" ]
ENTRYPOINT [ "git" ]

Dockerfile
=========
FROM ubuntu
MAINTAINER bhanu
WORKDIR /app1
COPY run.sh /app1
RUN chmod +x /app1/run.sh
ENV JAVA_HOME=/usr/bin/java
ENTRYPOINT ["./run.sh"]
CMD ["arg1"]

run.sh
=====
#!/bin/bash
echo "The current working directory" $(pwd)
echo "env variable nameis " $JAVA_HOME
echo "There are $# arguments" $@

You might also like