Docker
Virtualization
Docker
Docker image
Docker Architecture
Installation
The Docker Comunity package is now called “docker-ce“. Let’s add the CE repository for
docker installation.
Centos-7 & RHEL-7
# yum -y install
wget
# wget https://download.docker.com/linux/centos/docker-ce.repo -
O
/etc/yum.repos.d/docker-
ce.repo
Install the latest version of Docker CE using the following command.
#yum
repolist
# yum -y install docker-
ce
Ubuntu-16
#sudo apt-get update
#sudo apt-get install docker.io –y
Start and stop Docker
#service docker start
#service docker stop
Docker commands
#sudo docker version
#sudo docker info
Docker Hub
https://hub.docker.com/
Docker Images
Running a docker image (or) downloading images
#sudo docker run hello-world
Running a ubuntu image
#Docker run –it Ubuntu bash
Here you are telling Docker to run the command in the interactive mode via
the –it option.
Displaying docker images
#docker images
Removing a docker image
#docker rmi ImageID
docker rmi $(docker images -a -q) --remove all images
docker run --rm image_name -- remove after run
Inspect an images
#docker inspect imagename
Containers
Running a container
#sudo docker run –it centos /bin/bash
Listing containers
#docker ps
Listing all containers
#sudo docker ps -a
Docker history
#docker history ImageID
Top container
docker top ContainerID
stop a container
#docker stop conainerID
Remove a container
docker rm ContainerID
docker ps -a -f status=exited --list all stopped containers
docker rm $(docker ps -a -f status=exited) --remove all stopped containers
Container Stats
docker stats ContainerID
Attach a container
docker attach ContainerID
Pause a container
docker pause ContainerID
UnPause a container
docker unpause ContainerID
Kill a container
docker kill ContainerID
docker inspect
#docker inspect <container ID>
Running container in “interactive mode”
--- first start container
#docker start <container id>
---then ‘exec’
#docker exec -it <container id> bash
Docker – Container Lifecycle
The following illustration explains the entire lifecycle of a Docker container.
Linking containers
Source containers:
#docker pull Jenkins
#dokcer run –-name=jenkinsa –d Jenkins
Destination container:
#docker run - -name=reca - -link=jenkinsa:alias-src –it ubuntu /bin/bash
#env
#mongo 172.17.0.2:27017
Mongo DB image
#docker pull mongo
#docker run –it –d mongo
#docker run –it --link=client_sys:mongo mongo /bin/bash
#docker inspect continerid
#mongo 178.13.0.10:27017
#use demo
nginix image
#docker pull nginix
#docker run –p 8080:80 –d nginix
Nagios
Install
docker pull jasonrivers/nagios:latest
Running
Run with the example configuration with the following:
docker run --name nagios4 -p 0.0.0.0:8080:80 jasonrivers/nagios:latest
alternatively you can use external Nagios configuration & log data with the following:
browser: http://localhost:8080
Credentials
The default credentials for the web interface is nagiosadmin / nagios
Networking
#docker network ls
#docker network inspect net-name
Ex:run image then check the above command
#docker network create –-driver bridge my_nw ..creates new n/w
#Docker run –it –network=my_nw ubuntu:latest
/bin/bash
Volumes
#docker system volume –v ..disk space used by docker
#docker info ..info about docker
#docker run --volume-driver=vol1 created tmp vol
# docker volume create --driver local \
> --opt type=tmpfs \
> --opt device=tmpfs \
> --opt o=size=100m,uid=1000 \
> --name=test-volume
#docker run –volume-driver=newdrive jenkins
#docker run --volume-driver=vol1 -v
/home/demo:/var/jenkins_home
Jenkins .. attch vol
#docker volume rm vol-id
#docker volume inspect vol-id
#docker volume prune ..remove unused volumes
Docker file...
● Create public repo in hub.docker.com
1.create docker file
2.docker build -t myimage:1.0
push... docker login docker tag imageid
publicrepo-name:1.0 docker push
publicrepo-name:1.0
Docker compose
Install docker-compose
#sudo curl -L
"https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname
-s)-$(uname -m)" -o /usr/local/bin/docker-compose
#sudo chmod +x /usr/local/bin/docker-compose
#docker-compose --version
#vi docker-compose.yml
version: '2'
services:
databases: image:
mysql ports: -
"3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=user
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=demodbweb:
image: nginx
#docker-compose up –d
#docker-compose ps
Rough Work
Creating a volume
docker volume create --driver local \
--opt type=tmpfs \
--opt device=tmpfs \
--opt o=size=100m,uid=1000 \
--name=test-volume