Wednesday, 2 November 2016

Installation and Basic Docker commands on ubuntu

Installation and Basic Docker commands on ubuntu

What is Docker?

     Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they're running on and only requires applications be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.

And importantly, Docker is open source. This means that anyone can contribute to Docker and extend it to meet their own needs if they need additional features that aren't available out of the box.


Docker Installation Step

# sudo apt-get install -y docker.io

Reading package lists... Done
Building dependency tree    
Reading state information... Done
The following packages were automatically installed and are no longer required:
  account-plugin-windows-live imagemagick-common libfftw3-double3 libilmbase6
  liblqr-1-0 libmagickcore5 libmagickcore5-extra libmagickwand5 libnetpbm10
  libopenexr6 libsdl-image1.2 libserf-1-1 libsvn1 libupstart1 nagios-images
  netpbm
Use 'apt-get autoremove' to remove them.
Suggested packages:
  btrfs-tools debootstrap lxc rinse
The following packages will be REMOVED:
  docker-engine
The following NEW packages will be installed:
  docker.io
0 upgraded, 1 newly installed, 1 to remove and 298 not upgraded.
Need to get 4,749 kB of archives.
After this operation, 72.1 MB disk space will be freed.
Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/universe docker.io amd64 1.6.2~dfsg1-1ubuntu4~14.04.1 [4,749 kB]
6% [1 docker.io 270 kB/4,749 kB 6%]                                          
Get:2 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/universe docker.io amd64 1.6.2~dfsg1-1ubuntu4~14.04.1 [4,749 kB]
Fetched 4,478 kB in 2min 9s (34.6 kB/s)                                      
(Reading database ... 205032 files and directories currently installed.)
Removing docker-engine (1.12.0-0~trusty) ...
docker stop/waiting
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Selecting previously unselected package docker.io.
(Reading database ... 204909 files and directories currently installed.)
Preparing to unpack .../docker.io_1.6.2~dfsg1-1ubuntu4~14.04.1_amd64.deb ...
Unpacking docker.io (1.6.2~dfsg1-1ubuntu4~14.04.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
ureadahead will be reprofiled on next reboot
Setting up docker.io (1.6.2~dfsg1-1ubuntu4~14.04.1) ...
Installing new version of config file /etc/init.d/docker ...
Installing new version of config file /etc/bash_completion.d/docker ...
Installing new version of config file /etc/default/docker ...
Installing new version of config file /etc/init/docker.conf ...
addgroup: The group `docker' already exists as a system group. Exiting.
docker start/running, process 12267
Processing triggers for ureadahead (0.100.0-16) ...

Basic Commands

1. To list the containers:
 $ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

2. To check the docker version:
$ docker --version
Docker version 1.6.2, build 7c8fca2

3. Very first command in docker:
$ sudo docker run busybox echo hello world
Unable to find image 'busybox:latest' locally
latest: Pulling from busybox
4185ddbe03f8: Pull complete 
b05baf071fd5: Pull complete 
Digest: sha256:65ce39ce3eb0997074a460adfb568d0b9f0f6a4392d97b6035630c9d7bf92402
Status: Downloaded newer image for busybox:latest
hello world

4. Listing container: 
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                      PORTS               NAMES
8f4a32c35516        busybox:latest      "echo hello world"   30 seconds ago      Exited (0) 29 seconds ago                       silly_mcclintock    

5. Listing Images: 
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
busybox             latest              b05baf071fd5        3 months ago        1.093 MB

6. Removing container: 
$ sudo docker rm 8f4a32c35516
   8f4a32c35516

7. Listing docker images: 
$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
busybox             latest              b05baf071fd5        3 months ago        1.093 MB

8. Ensure: 
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

9. Removing docker images: 
$ sudo docker rmi busybox
Untagged: busybox:latest
Deleted: b05baf071fd542c3146f08e5f20ad63e76fa4b4bd91f274c4838ddc41f3409f8
Deleted: 4185ddbe03f83877b631b5e271a02f6f232de744ae4bfc48ce44216c706cb7fd

10. To create ubuntu container: 
$ sudo docker run -t -i ubuntu:14.04 /bin/bash
Unable to find image 'ubuntu:14.04' locally
14.04: Pulling from ubuntu
bb04ed60c038: Pull complete 
0812a82a4eba: Pull complete 
f6662ef795ac: Pull complete 
39a955bdc1e1: Pull complete 
348ae5f2350a: Pull complete 
35b394a6f7a2: Pull complete 
Digest: sha256:1fcd5a92f26ef71ae47c6ee7894cea5c854461b63f2d391d1fc068438d847aa5
Status: Downloaded newer image for ubuntu:14.04
root@f462ca19e571:/# ls               
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

No comments:

Post a Comment