Professional Documents
Culture Documents
Docker 1
Docker 1
-------------------------------
An image is a collection of bin/lib that are necessary for an application to
run.All the docker images are present in the cloud site of docker called
hub.docker.com
Docker Components
---------------------
Dcoker Host:This is the machine where docker is installed
and all the docker images are downloaded.
Docker Client: This is the terminal of docker where we can fire the docker commands
Docker Registry:This is the cloud site of docker where all the docker images are
present.
hub.docker.com
We can also create a private registry whcih can be accessed
only by our organisation
10 To stop a container
docker stop containername/containerid
11 To start a container
docker start containername/containerid
12 To restart a container
docker restart containername/containerid
To restart a container after 20 seconds
docker restart -t 20 containername/containerid
13 To initialise a container
docker run imagename
Run command options
-------------------
-it Opens an interactive terminal in the container where we can fire
linux commands
-d Start the container in detached mode as a background
process(deamon)
-p Used for port mapping it it will bind the port of docker host with
the port of the container.Dcoker host port is called external
port,container port is called internal port
Eg: -p 8080:80
here 8080 is external port ie dockerhost port
80 is internal port ie docker container port
-P Will publish the port numbers.ie docker will map the internal port
of the container with an external port on the docker host and this external
port will be some number greater than 30000
-v Used for mounting volumes into the container
--volumes-from Used for creating reusable volumes that can be shared
between multiple containers
--network Used for associating a container with a specific network
--name Used for assigning a name for a container
-e Used for passing environment variables to the containers
-rm Used for deleting the container on exit from the container
23 To remove a network
docker network rm networkname/networkid
UseCase1
----------
Start an nginx container in detached mode and name it webserver.Map the external
port of docker host 8080 with internal port 80 of container
UseCase2
---------
Start a tomcat container and publish the port numbers,and git it a name mytomcat
1 Start tomcat
docker run --name mytomcat -d -P tomcat
UseCase4
---------
Start mysql as a container.Go into its interactive terminal
and login into the database,Create some sql tables
2 Use dockerfile
UseCase5
------------
Create a ubuntu container and install git in it
Save that container as an image(snpashot)
Start a container frm this new image and we should find git
installed on it
2 In the container
apt-get update
apt-get install -y git
exit
Docker Volumes
---------------
Since docker containers are for temporary usage,once the container is removed all
the data stored in the container will be lost.To preserve the data we can use
docker volumes
UseCase6
---------
Create a empty folder /intelliq.
Start an ubuntu container and mount /intelliq folder on it
Create some files in /intelliq in the contianer
Stop and remove the container,we should still be able to access the files
1 Create a directory
mkdir /intelliq
UseCase7
----------
Create a directory /intelliq
and mount it on centos container c1.Create some files in the intelliq folder in the
c1 container
Create another 2 container c2 and c3
These two containers should use the voulmes that are used by c1
1 Create a directory
mkdir /intelliq
3 Start another centos container c2 and this should use the volumes used by c1
docker run -it --name c2 --volumes-from c1 centos
In the c2 container
cd intelliq
touch file3 file4
Come out of the container without exit(Ctrl+p,Ctrl+q)
4 Start another centos container c3 and this should use the volumes used by c2
docker run -it --name c3 --volumes-from c2 centos
In the c3 container
cd intelliq
touch file5 file6
Come out of the container without exit(Ctrl+p,Ctrl+q)
5 Go into any of the three containers and we will see all the files created by
all the three contaieners
docker attach c1
cd intelliq
ls
--link option
--------------
This is a depricated way of creating contianer architecture
We can link multiple docker containers and passdata between them
UseCase 8
----------
Start 2 busybox contianers and link them with each other
UseCase 10
-----------
Create a setup for implementing ci-cd through jenkins
UseCase11
---------
Start a jenkins container and link it with an ubuntu contianer.Make this ubuntu as
a slave
Creating QA environment
--------------------------
Usecase12
-----------
Start a selenium hub container
Start 2 selenium node containers and link them with the selenium hub container
Run the selenium testing programs
2 Start a node which has firefox installed on it and link with hub container
docker run -d --name firefox --link hub:selenium -P -e
HUB_HOST=hub selenium/node-firefox-debug
3 Start another node which has chrome installed on it and link with hub
container
docker run -d --name chrome --link hub:selenium -P -e HUB_HOST=hub
selenium/node-chrome-debug
All the containers that we want to start and link are given in the compose file in
the form of services.All these services can be started or stopped using one single
command
chmod +x /usr/local/bin/docker-compose
Sample.yml file
----------------
---
intelliq:
- trainers:
- sai:
- Course: Devops
- fee: 12000
- sheshi:
- Course: AWS
- fee: 10000
- coordinator:
- shailaja
...
UseCase 13
----------
Create a docker compose file for linking a wordpress contianer with mysql contianer
vim docker-compose.yml
---
version: '3'
services:
intelliq-mysql:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: intelliq
intelliq-wordpress:
image: wordpress
ports:
- 5050:80
...
UseCase 14
-----------
Create docker compose file for starting a jenkins contianer and link with two
tomcat containers so that we can implement CI-CD
vim docker-compose.yml
version: '3'
services:
jenkinsserver:
image: jenkins
ports:
- 6600:8080
qaserver:
image: tomcat
ports:
- 7700:8080
links:
- jenkinsserver
prodserver:
image: tomcat
ports:
- 8800:8080
links:
- jenkinsserver
UseCase15
-----------
Create a docker compose file for setup of the QA environment.Create seelnium hub
container and link it with two node contianers
vim docker-compose.yml
version: '3'
services:
hub:
image: selenium/hub
ports:
- 4444:4444
firefox:
image: selenium/node-firefox-debug
ports:
- 5901:5900
environment:
HUB_HOST: hub
links:
- hub
chrome:
image: selenium/node-chrome-debug
ports:
- 5902:5900
environment:
HUB_HOST: hub
links:
- hub
Dockerfile
-----------
This is a simple text file which is used for creating dockerimages.It uses a syntax
called GO which has certain predefined keywords
MAINTAINER This is the name of the person or the organisation that has
created this dockerfile
CMD This is the default instruction that gets executed when the container is
started
RUN This is used for package management ie installing or uninstalling s/w using
apt or yum package managements
ADD This is used to copy files from the host machine to the docker container or
to download some files from a remote url
EXPOSE This is used for specifing what internalport of the container has to
exposed to the outside world
USER This is used to specify the default user credentials through which we
want to login into a container
WORKINGDIR This is used to specify the directory where the CMD instruction should
be executed
Create dockerfile from ubuntu base image ,specify the maintainer and give the
default instruction to execute
vim dockerfile
FROM ubuntu
MAINTAINER intelliq
CMD ["date"]
Create a dockerfile from ubuntu base image and make the default process as
reading /etc/passwd
vim dockerfile
FROM ubuntu
MAINTAINER intelliq
ENTRYPOINT ["/bin/cat"]
CMD ["/etc/passwd"]