Docker:
From a long time, i was quite fascinated by the way docker works and unfortunately i dint get a part of it, why the hell it can't run with windows directly (without installing boot2docker). This really challenges me to learn it from upside down and i embark my Journey to a great component called LXC in Linux. Believe me, you would understand DOCKER very easily if you know how LXC worked. Finally, i got to know DOCKER is just a way of managing your dockers in a better manner with some cherries on the cake like repository etc.
Here are my summarized notes, that anyone can learn from. I tried to keep them crisp and short. It is for just giving DOCKER a try and at least have a spoonfull of the dish.
From a long time, i was quite fascinated by the way docker works and unfortunately i dint get a part of it, why the hell it can't run with windows directly (without installing boot2docker). This really challenges me to learn it from upside down and i embark my Journey to a great component called LXC in Linux. Believe me, you would understand DOCKER very easily if you know how LXC worked. Finally, i got to know DOCKER is just a way of managing your dockers in a better manner with some cherries on the cake like repository etc.
Here are my summarized notes, that anyone can learn from. I tried to keep them crisp and short. It is for just giving DOCKER a try and at least have a spoonfull of the dish.
Docker installation:
$ sudo apt-get
update
$ sudo apt-get install docker.io
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
$ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
$ sudo apt-get install docker.io
$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
$ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
Sudo docker search
ubuntu -> search for keyword docker
Sodu docker pull
ubuntu -> to Pull all ubuntu images from Docker
Sudo docker images
-> show the list of all images
sudo docker run -i
-t ubuntu /bin/bash -> running the bash sheel correctly
# Start a new
container
JOB=$(sudo docker run -d ubuntu /bin/sh -c "while
true; do echo Hello world; sleep 1; done")
-> After above
command, the container will start and u have to press Ctrl-C to come out of it
and then have to you docker ps to see it
is running.
# Stop the container
docker stop $JOB
# Start the
container
docker start $JOB
# Restart the
container
docker restart $JOB
# SIGKILL a
container
docker kill $JOB
# Remove a container
docker stop $JOB # Container must be stopped to
remove it
docker rm $JOB
Installation of
Shipyard. ->
Installation of
apache/nginx ->
- sudo docker
run -i -t -p 80:80 ubuntu /bin/bash
NOw you will be entered in the shell. Press CTRL-P & CTRL-Q aftewards to come out of the shell - Sudo docker
ps
THis will list the container ID of the process
- Sudo docker
attach 3edaace90360
This will take you to the shell. - Sudo apt-get
update
As the image you have download is older one, so you will need to update the package list. - sudo apt-get
install apache2
This will install the apache on the system. - Sudo service apache2 start
- Sudo apt-get install curl
- Curl http://localhost
It will show the complete Apache Page.
sudo docker
commit 3edaace90360 panbhatt/pankaj_ubuntu_apache
This will store all the changes in that container by this name
This will store all the changes in that container by this name
Sudo docker images
It will list the
image that is just created with the name same.
Sudo docker login
This will prompt for
the docker username and password.
sudo docker push panbhatt/ubuntu-apache
This will push the
image to the docker repository
Sudo docker inspect 3edaace90360
This will list the
complete setting of the container (e.g. the network ports being exposed).
sudo docker port
3edaace90360 80
This will show
whether the port 80 is being used by the container or not
You can also
establish the LINKING Between the server, see section 2.3.1 of Docker
documentation
Networking
sudo apt-get install bridge-utils (to install brtcl on ubuntu)
Sudo brctl show
(see networking for Ubuntu, how docker establish the DOCKER brdige)
Sudo ifconfig docker0 -> To see the details
of the bridge. The set of IP addres to be given to continers
You can also control
the list of IP addresses need to be given to the docker. 2.4 section
Docker can also
provide a functionality to allow communication between the various contains, by
using -icc parameter which can be set
true/false in the bridge configuration.
Pipework project is
an great work at Github to connect multiple
containers
You can always make
sure that your containers are running with process managers like systemD,
upstart & supervisor . Check docker documentation for 2.5 for this.
Shared director or
VOLUME is the best way to share the directories from one container to another,
(even if the source container is not working at all).
You can also mount a
HOST directory to an container too. This will allow it to use any available
configuration or properties directory to the host system.
DockerFile
- Touch Dockerfile
- Write the following contents,
see documentation for greater detail.
# DOCKER-VERSION 1.0.1
FROM ubuntu:14.10
RUN sudo apt-get update
RUN sudo apt-get install -y
nginx
RUN sudo apt-get install -y curl
RUN sudo service nginx restart
EXPOSE 80
- Build the image by running
the following command
sudo docker build -t panbhatt/ubuntu_nginx_df .
if it says -> "Successfully built fc09cc5af0c5"
use "sudo docker images" to see your name of this VM is there. - Now Run this image:
sudo docker run -i -p 8000:80 -t panbhatt/ubuntu_nginx_df /bin/bash
Now attach yourself to this and enjoy.