0% found this document useful (0 votes)
12 views9 pages

Docker

Uploaded by

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

Docker

Uploaded by

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

Docker

Q. What is Docker?

Docker is a open source tools to make it easier to create, deploy, and run applications by us-
ing containers.

Q. What is Docker Image?

An image is a lightweight, stand-alone, executable package that includes everything needed


to run a piece of software, including the code, a runtime, libraries, environment variables,
and config files.

Q. What is a Docker Container?

A container is a runtime instance of an image, It runs completely isolated from the host envi-
ronment by default, only accessing host files and ports if configured to do so.

Q. What is the difference between Docker image and Docker con-


tainer?

Docker container is the runtime instance of docker image.


Docker Image doesn’t have a state and its state never changes.

Q. What is Docker-Compose?

Compose is a tool for defining and running multi-container Docker applications. With Com-
pose, you use a Compose file to configure your application’s services. Then, using a single
command, you create and start all the services from your configuration.

Q. What’s the difference between up, run, and start?

Docker compose uses UP command to start all container defined inside yml file.
Docker command line uses RUN to start container from docker image.
Docker command line uses START to start container from stoped state.

Q. Installation

We are using only community edition (CE)


vim /usr/lib/systemd/system/docker.service ## add this below line
ExecStart=/usr/bin/dockerd –storage-driver devicemapper

systemctl enable docker


systemctl start docker
docker pull centos
docker info

## below line using for creating custom network


docker network create –driver=bridge –subnet=172.20.50.0/24 –ip-range=172.20.50.0/
24 –gateway=172.20.50.1 jcb

Here JCB is network nameyum install -y yum-utils


yum-config-manager --add-repo https://download.docker.com/linux/centos/
docker-ce.repo
yum-config-manager --enable docker-ce-edge
yum install docker-ce -y

vim /usr/lib/systemd/system/docker.service ## add this below line


ExecStart=/usr/bin/dockerd --storage-driver devicemapper

systemctl enable docker


systemctl start docker
docker pull centos
docker info

## below line using for creating custom network


docker network create --driver=bridge --subnet=172.20.50.0/24
--ip-range=172.20.50.0/24 --gateway=172.20.50.1 jcb

Here JCB is network name

--storage-driver devicemapper this line needed because as you can see below screenshot
on centos it only supports devicemapper and by default it start with overlay2
Q. Docker Basics

## To check running containers


docker ps
docker ps -a ## with running, exited, created and dead container state

## To start container from image


docker run -it imageid_or_tag:repository /bin/bash
## Or you can use -itd to start in demonized mode and later you can do
docker attach container_id
## this attach will work only when docker first process will be /bin/bash or any shell

## To build docker container ## here . represents Dockerfile


docker build -t tag:repository .

## to run any command inside running container


docker exec container_id command
docker exec container_id ls -l /usr/local/goibibo

## To stop container
docker stop container_id

## To delete stopped container


docker rm container_id

## to delete image
docker rmi -f imageid_or_tag:repository

## To remove all exited state all container


docker rm $(docker ps -a -q -f status=exited)

## To check any information about container ## because result is json you can use
format
docker inspect container
docker inspect –format ’{{ .NetworkSettings.IPAddress }}’ container_id

## To check docker networks list


docker network ls

## To check docker network in details


docker network inspect network_name

## To check stats of running container


docker stats ## to check stats of all running container
docker stats container_id ## to check specific container stats## To check local images
docker images

## To check running containers


docker ps
docker ps -a ## with running, exited, created and dead container state

## To start container from image


docker run -it imageid_or_tag:repository /bin/bash
## Or you can use -itd to start in demonized mode and later you can do
docker attach container_id
## this attach will work only when docker first process will be /bin/bash or any
shell

## To build docker container ## here . represents Dockerfile


docker build -t tag:repository .

## to run any command inside running container


docker exec container_id command
docker exec container_id ls -l /usr/local/goibibo

## To stop container
docker stop container_id

## To delete stopped container


docker rm container_id

## to delete image
docker rmi -f imageid_or_tag:repository

## To remove all exited state all container


docker rm $(docker ps -a -q -f status=exited)

## To check any information about container ## because result is json you can
use format
docker inspect container
docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_id

## To check docker networks list


docker network ls

## To check docker network in details


docker network inspect network_name

## To check stats of running container


docker stats ## to check stats of all running container
docker stats container_id ## to check specific container stats

## to check logs of running or exited container


docker logs container_id

## To start exited container


docker start container_id## To check running process inside docker container
docker top container_id

## to check logs of running or exited container


docker logs container_id

## To start exited container


docker start container_id

Dockerfile
Here every command(Like FROM, COPY, ADD......) will create a layer how many layer will be
image will be heavy.

FROM centos:latest

Dockerfile is help us to run command on base image and give us newly created image
So here centos:latest is our base image

MAINTAINER Anand Kumar Marthanda <[email protected]>

Its metadata and optional

RUN \
/usr/bin/bash /root/script.sh && \
rm -f /etc/localtime && \
ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime

RUN is used for run command inside image’s running container


And here we are running multiple command under single layer

COPY ["terminal/consoletype","terminal/initjs", "/sbin/"]


COPY terminal/functions /etc/rc.d/init.d/

COPY is simply copy file from host to inside image’s running container

ADD ["some.tar.gz","thing.tar.gz", "/tmp"]


ADD thing.tar.gz /tmp/

ADD will copy file untar it and remove tar file and you can also use it for download any thing
from link also

WORKDIR /jobs/foreMfore_deploy

WORKDIR say when you start container by default it will cd to this path for you
EXPOSE 8080 8040 8020 8090
CMD ["/usr/bin/supervisord", "-n"]

EXPOSE will expose port for host


CMD will start service inside container when container will start with pid 1 so this will be init
process of container

Deployment Process
Folder structure

So i created Four basics folder :

● entrypoint
● projectname (gocash)
● prodpp
● yml

Entrypoint : used for shell script


PROJECT NAME: used for to create docker image for that project
PRODPP : used for logs
YML : used for dockerfile and and compose file
ENTRYPOINT

bake-pp.sh is used by praneeth for bake source code in docker and upload artifacts to s3

TAG = jcb-1.1
ENV = pp
GOAL = deploy
PROJECT = mfore/bin/bash /docker/entrypoint/bake-pp.sh jcb-1.1 pp bake mfore

TAG = jcb-1.1
ENV = pp
GOAL = deploy
PROJECT = mfore

Internally based on project name i pick correct yml file and change tag inside yml file and
start compose file

deploy-prodp.sh is uded by praneeth for to deploy from s3 and start test cases but this shell
script take care of change tag inside yml file and start container

And one more import point is in both bake and deploy i use ansible because image should
created with jcb_tag so that if at any time its fail we can go inside docker based on jcb_tag
and debug it.
For every project i use only two yml file one for bake and another is deploy

BAKE : pull source code from github and compile and tar and upload into s3
DEPLOY : pull from s3 untar link to current and start services

Under /docker/prodpp/logs you will get logs of container service logs and its flush every
time during deployment process.

You might also like