You are on page 1of 2

####### Data volumes ######

1. Simple docker volumes


mkdir /data ***Create directory in host machine***
docker run --name u1 -it -v /data ubuntu

2. Sharable docker volumes


docker run --name c1 -it -v /data centos
docker run --name c2 -it --volumes-from c1 centos

3. Docker volume containers


docker volume create myvolume *** To create docker volumein host
machine***
docker volume inspect *** To get the detailed information
of the data volume created on the host machine***
docker run --name u1 -it -v myvolume:/tmp ubuntu **** To access the data
volume in the containers***

###### Creating docker images from Docker File #####

dockerfile ////docker file to customize images ..Images can be deleted once


dockerfile is created which will greatly save space ///

Executing dockerfile :

docker build -t mynginx . *** creates image from dockerfile in the


current directory***

dockerfile is created using some Keywords as below :

FROM
MAINTAINER
RUN [RUN apt-get install -y git ///Builts image with git app
installation ...RUNs the sripts]
EXPOSE [ EXPOSE 90 ///image with additional port will be created]
USER [USER root ///IMAGE with USER root will be created which will have
previliges to install softwares]
ADD [ADD https://get.jenkins.io/war-stable ...image will be created that
downloads from the given url]
COPY /// COPY script.sh / ...Copy the script from host machine to /root
directory in container
VOLUME [VOLUME /data ////iMAGE IS built that creates a volume when container is
created]
CMD [same as endpoint only difference is we can change the default
process of the container at the time of docker run ]
ENTRYPOINT [ to specify the default process of the container]

###### cache busting #######

docker build --no-cache -t myubuntu . (execute from the scratch)


##### Opening Container in Interactive terminal #####

docker exec -it j1 bash ////j1 is container name///

You might also like