Steps to Build, Run and Manage Docker

Docker is a software container that automates the applications deployment while providing an additional layer of OS-level virtualization automation on Linux. These docker containers are created using docker images, either by executing commands manually or automatically through Dockerfiles.

According to an industry analyst research, Docker is an efficient tool that packs an application and its dependencies in a virtual container that can operate on any Linux server. This process facilitates the flexibility and portability where the application is running.

Docker avoids the burden of maintaining virtual machine by allowing independent containers to operate within a single Linux instance, using Linux kernel resource isolation features such as kernel namespaces and cgroups.

How Docker is different from Virtual Machines?

Though resource isolation and allocation benefits of docker containers are similar to virtual machines, the different architectural approach of containers makes them more portable and efficient.


Advantages of Docker

  • Easy to move apps between cloud platforms
  • Distribute and share content
  • Accelerate developer onboarding
  • Empower developer creativity
  • Eliminate environment inconsistencies
  • Ship software faster
  • Easy to scale an application
  • Remediate issues efficiently

Installing Docker on Ubuntu

Update the droplet

sudo aptitude    update
sudo aptitude -y upgrade

Make sure the availability of aufs support

sudo aptitude install linux-image-extra-`uname -r`

For package verification, add docker repository key to apt-key

sudo sh -c "wget -qO- | apt-key add -"

Add the docker repository to aptitude sources

sudo sh -c "echo deb docker main\

> /etc/apt/sources.list.d/docker.list"

Update the repository with the new addition

sudo aptitude    update

Finally, download and install docker

sudo aptitude install lxc-docker


Proxy in Docker

Edit /etc/defaults/docker and add the following lines:

export http_proxy=''

After adding, restart the docker using the following comment:

$ sudo service docker restart

This will allow the docker daemon to pull images from central registry. However, to configure the proxy in Dockerfile (while using apt-get to install packages), you need to declare the comment there also.

Add the following lines at the top of your Dockerfile:

ENV http_proxy ''

ENV https_proxy ''



With these settings, your container should now build using the proxy to access the
outside world

Basic Docker Commands

Running the docker in daemon and CLI Usage

Upon installation, the docker daemon that is running in the background will be ready to accept commands sent by the docker CLI. During certain situations like running a docker manually, it is necessary to follow the below guidelines:

Run the docker in daemon mode

sudo docker -d &

Docker CLI Usage

sudo docker [option] [command] [arguments]

Commands List

Check out the provided list of docker commands:

attach         Attach to a running container
build          Build a container from a Dockerfile
commit         Create a new image from a container's changes
cp             Copy files/folders from the containers filesystem to the host path
diff           Inspect changes on a container's filesystem
events         Get real time events from the server
export         Stream the contents of a container as a tar archive
history        Show the history of an image
images         List images
import         Create a new filesystem image from the contents of a tarball
info           Display system-wide information
insert         Insert a file in an image
inspect        Return low-level information on a container
kill           Kill a running container
load           Load an image from a tar archive
login          Register or Login to the docker registry server
logs           Fetch the logs of a container
port           Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
ps             List containers
pull           Pull an image or a repository from the docker registry server
push           Push an image or a repository to the docker registry server
restart        Restart a running container
rm             Remove one or more containers
rmi            Remove one or more images
run            Run a command in a new container
save           Save an image to a tar archive
search         Search for an image in the docker index
start          Start a stopped container
stop           Stop a running container
tag            Tag an image into a repository
top            Lookup the running processes of a container
version        Show the docker version information
wait           Block until a container stops, then print its exit code


Command2 Command1

Example 1: An Interactive Container of tomcat server

Let’s try the docker run command again, with specifying a new command to run in our container.

$ sudo docker run --name ubuntu14  –p 8080:8080 -t -i tutum/tomcat /bin/bash

-t → pseudo-tty or terminal inside our new container

-i → interactive connection by grabbing the standard in (STDIN) of the container

/bin/bash → This will launch a Bash shell inside our container

-p → Port exposing

So, now when our container is launched, we can see a command prompt inside it.



Note: Change the port number of tomcat server in /tomcat/conf/server.xml file and restart the tomcat service in the container. Open the tomcat manager in a browser and deploy the applications.

Example 2: Run nginx container in the docker

To install and assign a port number for nginx, apply the following comment

docker run --name ngnix -p 81:81 -it nginx/nginx /bin/bash

Note: Change the default port number of ngnix server in /etc/nginx/sites-enabled/default file and restart the ngnix server.

To view the Docker monitor in a web browser:

Run the Docker UI command:

$ docker run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock dockerui/dockerui

To exit the container:

CTRL+P immediately followed by CTRL+Q

Committing changes to an image

To continue performing actions in a container such as download and install, configure files, etc. you need to “commit.” Committing ensures that everything (e.g. image) can be resumed during the next visit.

# Usage: sudo docker commit [container ID] [image name]

sudo docker commit 8dbd9e392a96 my_img



sudo docker export <CONTAINER ID> > /home/export.tar

Note: If we export the container, it will not copy history and meta-data. Hence, the file size may be less than 5MB.


$ sudo docker save busybox-1 > /home/save.tar

Note: It will save the container’s history and meta-data. Hence, the file size will be slightly more, when compared to export.

How to Limit the Memory Usage for Containers?

In order to limit the memory usage, simply set –m [memory amount] flag in a docker container.

To run a container with memory limited to 256 MBs:

# Example: docker run -name [name] -m [Memory (int)][memory unit (b, k, m or g)] -d (to run not to attach) -p (to set access and expose ports) [image ID]

docker run -m 64m -d -p 8082:80 tutum/wordpress

To confirm the memory limit, you can inspect the container:

# Example: docker inspect [container ID] | grep Memory

docker inspect 9a7562a361122706 | grep Memory

Hence, it is one of the major technology innovations, which provides enterprises with significant revenue improvements. It transforms the way you deploy, manage and migrating applications in the cloud and is always a right tool for your enterprise.


About Gadepalli Manikanta Kamal

Gadepalli Kamal is a software developer at Vmoksha Technologies who has in-depth experience in advanced Java. He is passionate about researching and implementing new technologies and completed several projects successfully applying the emerging technologies. Besides staying updated on new trends, he loves painting and writing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>