0% found this document useful (0 votes)
72 views7 pages

Docker

The document outlines the steps to set up and manage Docker on a CentOS system, including creating a Docker repository, installing Docker, and managing Docker images and containers. It details commands for pulling images, running containers, and performing operations like stopping, starting, and removing containers and images. Additionally, it includes instructions for creating and committing changes within a container, as well as pushing images to Docker Hub.

Uploaded by

hasan502
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)
72 views7 pages

Docker

The document outlines the steps to set up and manage Docker on a CentOS system, including creating a Docker repository, installing Docker, and managing Docker images and containers. It details commands for pulling images, running containers, and performing operations like stopping, starting, and removing containers and images. Additionally, it includes instructions for creating and committing changes within a container, as well as pushing images to Docker Hub.

Uploaded by

hasan502
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/ 7

[root@ip-172-31-17-186 /]# cd /etc/yum.repos.

d/

[root@ip-172-31-17-186 yum.repos.d]# ls

redhat-rhui-client-config.repo redhat-rhui.repo rhui-load-balancers.conf

[root@ip-172-31-17-186 yum.repos.d]# vi docker.repo


[root@ip-172-31-17-186 yum.repos.d]# cat docker.repo

[dockerrepo]

name=DOCKER REPOSITORY

baseurl=https://yum.dockerproject.org/repo/main/centos/7/

enabled=1

gpgcheck=1

gpgkey=https://yum.dockerproject.org/gpg

[root@ip-172-31-17-186 yum.repos.d]# yum install docker-io -y

[root@ip-172-31-17-186 yum.repos.d]# service docker status

[root@ip-172-31-17-186 yum.repos.d]# service docker restart

[root@ip-172-31-17-186 /]# ifconfig

docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500

inet 172.17.0.1 netmask 255.255.0.0 broadcast 0.0.0.0

inet6 fe80::42:bdff:fe19:6deb prefixlen 64 scopeid 0x20<link>

ether 02:42:bd:19:6d:eb txqueuelen 0 (Ethernet)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 3 bytes 258 (258.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001

inet 172.31.17.186 netmask 255.255.240.0 broadcast 172.31.31.255

inet6 fe80::f9:60ff:fee1:47e0 prefixlen 64 scopeid 0x20<link>

ether 02:f9:60:e1:47:e0 txqueuelen 1000 (Ethernet)

RX packets 252565 bytes 372789141 (355.5 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 43310 bytes 3481733 (3.3 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@ip-172-31-17-186 /]# docker version or docker --version

[root@ip-172-31-17-186 /]# docker search ubuntu


[root@ip-172-31-17-186 /]# docker search centos

[root@ip-172-31-17-186 /]# docker pull ubuntu

[root@ip-172-31-17-186 /]# docker pull centos

[root@ip-172-31-17-186 /]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

centos latest 5182e96772bf 36 hours ago 200MB

ubuntu latest 735f80812f90 12 days ago 83.5MB

### To remove the image from the host ###

[root@ip-172-31-17-186 /]# docker rmi ubuntu

[root@ip-172-31-17-186 /]# docker rmi -f ubuntu

[root@ip-172-31-17-186 /]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

centos latest 5182e96772bf 36 hours ago 200MB

### To view the docker process ###

[root@ip-172-31-29-169 ~]# docker ps

[root@ip-172-31-29-169 ~]# docker ps -a

[root@ip-172-31-29-169 ~]# docker ps -l

### Connect to a container with "unique-name"

[root@ip-172-31-29-169 ~]# docker run --name CG-App -it acaccf95a1ec[root@ip-172-31-


29-169 ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED


STATUS PORTS NAMES

548a70859993 acaccf95a1ec "/bin/bash" About a minute ago Up


About a minute CG-App

### To stop, start, attach & kill a container ###

[root@ip-172-31-29-169 ~]# docker stop 548a70859993

548a70859993
[root@ip-172-31-29-169 ~]# docker kill 548a70859993

548a70859993

[root@ip-172-31-29-169 ~]# docker start 548a70859993

548a70859993

[root@ip-172-31-29-169 ~]# docker attach 548a70859993

root@548a70859993:/#

### To View IpAdd & MacAdd ###

[root@ip-172-31-29-169 ~]# docker inspect --format '{{ .NetworkSettings.IPAddress }}'


d0722775bea4

172.17.0.2

[root@ip-172-31-29-169 ~]# docker inspect --format '{{ .NetworkSettings.MacAddress }}'


d0722775bea4

02:42:ac:11:00:02

### To remove container ###

[root@ip-172-31-29-169 ~]# docker rm -f $(docker ps -a -q)

### To remove images ###

[root@ip-172-31-29-169 ~]# docker rmi -f $(docker images -q)

### Docker commit ####

[root@ip-172-31-29-169 ~]# docker run -it ubuntu


root@c785b11ae432:/# hostname

c785b11ae432

root@c785b11ae432:/# ls

bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv
sys tmp usr var

root@c785b11ae432:/# cd /home/

root@c785b11ae432:/home# ls

root@c785b11ae432:/home# mkdir 2-Tier-Applications

root@c785b11ae432:/home# cd 2-Tier-Applications/

root@c785b11ae432:/home/2-Tier-Applications# touch web-server db-server web-logic-


server

root@c785b11ae432:/home/2-Tier-Applications# ls

db-server web-logic-server web-server

root@c785b11ae432:/home/2-Tier-Applications# touch server-logs-a.0.{1..10}

root@c785b11ae432:/home/2-Tier-Applications# ls

db-server server-logs-a.0.10 server-logs-a.0.3 server-logs-a.0.5 server-


logs-a.0.7 server-logs-a.0.9 web-server

server-logs-a.0.1 server-logs-a.0.2 server-logs-a.0.4 server-logs-a.0.6 server-


logs-a.0.8 web-logic-server

[root@ip-172-31-29-169 ~]# docker commit c785b11ae432 svimal/my-repository

sha256:2fa6feb16281eab09d3ec3b66a08d04b264e71ed53ad1bc6a09878a52fcb48f0

[root@ip-172-31-29-169 ~]# docker login

Login with your Docker ID to push and pull images from Docker Hub. If you don't have a
Docker ID, head over to https://hub.docker.com to create one.

Username (svimal): svimal

Password:

Login Succeeded

[root@ip-172-31-29-169 ~]# docker push svimal/my-registory

The push refers to repository [docker.io/svimal/my-registory]

f862d925af87: Pushed

ec8257ff6a7a: Mounted from library/ubuntu

7422efa72a14: Mounted from library/ubuntu


b6a02001ba33: Mounted from library/ubuntu

a26724645421: Mounted from library/ubuntu

a30b835850bf: Mounted from library/ubuntu

latest: digest:
sha256:24656a6a8d78c5148d77878f49c977138eb75b9444cd15b7209942e45221aed5 size: 1564

[root@ip-172-31-29-169 ~]# docker images

REPOSITORY TAG IMAGE ID CREATED


SIZE

svimal/my-repository latest acaccf95a1ec 8 minutes


ago 84.1MB

svimal/my-repository/ubuntu-vms latest 2fa6feb16281 11 minutes

[root@ip-172-31-29-169 ~]# docker run -it 2fa6feb16281

root@7471d7ff983c:/# ls /home

2-Tier-Applications

You might also like