Installing
and Configuring Docker
Video
Main
Tasks
1.Install
Docker
2.Install
CONTAINER
3.Starting
CONTAINER
4.
Copying files to & from CONTAINER
5.
Installing webserver in CONTAINER and
acccessing it
6.
Saving Docker image
7.
Building Docker image
8.Exporting
and importing docker images
1.1
Add docker repo
vi
/etc/yum.repos.d/docker.repo
File
should be like :
A.
For centos , similar to RHL distribution
[dockerrepo]
name=Docker
Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
B.
For Ubuntu : deb distribution
-
sudo apt-get install apt-transport-https ca-certificates
-
sudo vi /etc/apt/sources.list.d/docker.list
sudo
apt-get install apt-transport-https ca-certificates
docker.list
should contains
deb
https://apt.dockerproject.org/repo ubuntu-xenial main
-
sudo apt-get install linux-image-extra-$(uname -r)
-
sudo apt-get install docker.io
sudo apt-get update
sudo
apt-get purge lxc-docker
sudo
apt-cache policy docker-engine
1.2
Install via yum
yum
install docker-engine
1.3
Add init.d for server to come up automatically after reboot
chkconfig
docker
on
in Ubuntu
sudo systemctl enable docker
1.4
Start the docker process
service
docker start
2.
Install docker CONTAINER
2.1
: Pull the latest centos
docker
pull centos
SnapShot
:
Using
default tag: latest
latest:
Pulling from library/centos
3d8673bd162a:
Pull complete
Digest:
sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4
Status:
Downloaded newer image for centos:latest
3.Starting
CONTAINER
3.1
start
the container process
docker
run -it centos
[root@localhost ~]# docker
run -it centos
[root@8b173a99e5f7 /]#
[root@8b173a99e5f7 /]#
uname -a
Linux 8b173a99e5f7
3.10.0-327.el7.x86_64 #1 SMP Thu
Nov 19 22:10:57 UTC 2015 x86_64
x86_64 x86_64
GNU/Linux
[root@8b173a99e5f7 /]#
4.
Copying files to & from CONTAINER
From Host OS to CONTAINER
(push )
docker
cp
<Container>
:/root/Fromdocker.tiff
.
From CONTAINER to Host
docker
cp
<Container>
:/root/Fromdocker.tiff
/
home/oracle
5.
Installing webserver in CONTAINER
and acccessing it .
In
container
5.1
yum
install httpd
Create
simple cgi script
vi
/var/www/cgi-bin/date.cgi
#!/bin/bash
echo
"Content-type: text/html"
echo
""
echo
"<html><head><title>SERVER STATUS "
echo
"</title></head><body>"
echo
"<h1> SERVER PINGS </h1>"
echo
"</body></html>"
Start the http process in
CONTAINER
/usr/sbin/httpd
This
will show the ip address
AH00558:
httpd: Could not reliably
determine the server's fully qualified
domain name, using 172.17.0.2. Set the
'ServerName' directive
globally to
suppress this message
Other
method is in host server run
docker
inspect 8b173a99e5f7 | grep IPAddress
Access
http server from Host
wget
http://172.17.0.2/cgi-bin/date.cgi
To
access outside of HOST OS , you need to SSH tunnening
ssh
-N -L <OUTSIDEPORT>:<CONTAINERIP:PORT> username@<HOSTOS>
Example
: ssh -N -L 8080:172.17.0.2:80 root@172.16.102.142
Another
option is save the image and start with port forwarding .
6.
Saving Docker image
6.1
docker
images
docker
images
REPOSITORY
TAG IMAGE ID CREATED
SIZE
centos
latest 970633036444 16 hours ago
196.7 MB
6.2
docker
comit <CONTAINER> repo:TAG
docker
commit 8b173a99e5f7 centos:httpd
docker
images
REPOSITORY
TAG IMAGE ID CREATED
SIZE
centos
httpd 77e976c360ed 4 seconds ago
664.1 MB
centos
latest 970633036444 16 hours ago
196.7 MB
6.3
stoping
CONTAINER
docker
stop 8b173a99e5f7
docker
ps
shows
all running CONTAINER
6.4
starting docker with httpd process
docker
run -d -p 80:80 centos:httpd /usr/sbin/httpd -D FOREGROUND
after
this web server can be access via host server
port .
7.
Building Docker image
7.1
Creating docker file
vi
Dockerfile
FROM
centos:httpd
MAINTAINER
A D Ministator email: user@master.company.com
EXPOSE
80
ENTRYPOINT
/usr/sbin/httpd -D FOREGROUND
Expose
80 , it will open port 80 from container
Entry
point command to in docker, in foreground
7.2
Bulding image
Option
A
docker
build -t centos:httpd .
Sending
build context to Docker daemon 2.048 kB
Step
1 : FROM centos:httpd
--->
ea0a5995178a
Step
2 : MAINTAINER A D Ministator email:
user@master.company.com
--->
Running in 1237e8916daa
--->
60c37cb46920
Removing
intermediate container 1237e8916daa
Step
3 : EXPOSE 80
--->
Running in fc4ca921a05b
--->
d39d12367bfa
Removing
intermediate container fc4ca921a05b
Step
4 : ENTRYPOINT /usr/sbin/httpd -D
FOREGROUND
--->
Running in f04320581760
--->
cee47177f39f
Removing
intermediate container f04320581760
Successfully
built cee47177f39f
7.3.1
Starting options
docker
run
-it centos:httpd
this
will start process in foreground , and promt will be open and no
access to server .
[root@localhost
httpd]# docker run -it centos:httpd
AH00558:
httpd: Could not reliably determine the
server's fully qualified
domain name, using
172.17.0.2. Set the 'ServerName' directive
globally to
suppress this message
Clt+C
is required to stop the process .
7.3.2
with using -d -P option , this will run in back
ground with opening
new port is host to access it
docker
run -it -d -P centos:httpd
[root@localhost
httpd]# docker run -it -d -P
centos:httpd
44ef230f4eb2d127194ad6983d740516312c87781fd2bb61c60148556c49c84d
[root@localhost
httpd]# docker ps
CONTAINER
ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
44ef230f4eb2
centos:httpd "/bin/sh -c '/usr/sbi" About
a
minute ago Up About a minute 0.0.0.0:32771->80/tcp
determined_hugle
Outside
of Host can be access this via port 32771 .
To
stop this get the docker CONTAINER ID and stop
it
Option
B : To start the httpd server and get
interactive mode to work
Change
the Docker file
7.4
vi
Dockerfile
FROM
centos:httpd
MAINTAINER
A D Ministator email:
user@master.company.com
RUN
echo "/usr/sbin/httpd" >> /root/.bashrc
EXPOSE
80
ENTRYPOINT
/bin/bash
7.5
docker
build -t centos:httpd
Sending
build context to Docker daemon 2.048 kB
Step
1 : FROM centos:httpd
--->
e16e66235220
Step
2 : MAINTAINER A D Ministator email:
user@master.company.com
--->
Running in b4b55bb424b6
--->
7a2872939817
Removing
intermediate container b4b55bb424b6
Step
3 : RUN echo "/usr/sbin/httpd" >> /root/.bashrc
--->
Running in 8ea971955893
--->
954b2ffbefa3
Removing
intermediate container 8ea971955893
Step
4 : EXPOSE 80
--->
Running in 798f8f742615
--->
39484e2d99b3
Removing
intermediate container 798f8f742615
Step
5 : ENTRYPOINT /bin/bash
--->
Running in 25568d2988f0
--->
519165f43eda
Removing
intermediate container 25568d2988f0
Successfully
built 519165f43eda
7.6
to start
docker
run -it centos:httpd
[root@localhost
httpd]# docker run -it centos:httpd
AH00558:
httpd: Could not reliably determine the
server's fully qualified
domain name, using
172.17.0.2. Set the 'ServerName' directive
globally to
suppress this message
[root@f86f2c71b543
/]#
[root@f86f2c71b543
/]# exit
exit
8.Exporting
and importing docker images
8.1
exporting
docker
save
centos:httpd
> http.tar
ls -l -h http.tar
-rw-r--r--.
1 root root 643M Jul 30 06:52 http.tar
Copy
this to other docker server
Import
8.2
importing
docker
load
<
http.tar
No comments:
Post a Comment