Basic Docker Installation with Simple Project using Docker and Pushed to Docker Hub

Shahjalal
Oceanize Lab Geeks
Published in
7 min readJun 25, 2019

What is Docker?

Docker is not virtual machines. There’s only a single operating system running. That operating system is just carved up into isolated little spaces. A container is a self-contained sealed unit of software. It has everything in it that is needed to run that code. I mean all of it, batteries included, operating system included, it has all of the code, all of the configs, contains all the processes within that container, it has all of the networking to allow these containers to talk to the other containers they’re supposed to be able to talk to, and nothing else.

It has all the dependencies that your system needs, bundled up in that container. And it even includes just enough of the operating system to run your code. So the way it works, it takes all the services that make up a Linux server. Networking, storage, code, inter process communication, the whole works, and it makes a copy of that in the Linux Kernel for each container. So each container has its own little world that it can’t see out of, and other containers can’t see in.

Docker is a client program, named Docker, it’s a command you type at the terminal. It’s also a server program that listens for messages from that command, and manages a running Linux system. Docker has a program which builds containers from code. It takes your code along with its dependencies and bundles it up and then seals it into a container. And it’s a service that distributes these containers across the internet and makes it so you can find other’s work, and the right people can find your work.

In Docker have some key concept that is

1. Image

2. Layer

3. Container

What is an image in Docker?

An image is an inert, immutable, file that’s essentially a snapshot of a container. Images are created with the build command, and they’ll produce a container when started with run. Images are stored in a Docker registry such as registry.hub.docker.com. Because they can become quite large, images are designed to be composed of layers of other images, allowing a miminal amount of data to be sent when transferring images over the network.

What is Container in Docker?

An instance of an image is called a container. You have an image, which is a set of layers as we describe. If we start this image, we have a running container of this image. We can have many running containers of the same image. Containers are lightweight and portable encapsulations of an environment in which to run applications.

What is Layer in Docker?

Basically, a layer, or image layer is a change on an image, or an intermediate image. Every command you specify (FROM, RUN, COPY, etc.) in your Dockerfile causes the previous image to change, thus creating a new layer.

The concept of layers comes in handy at the time of building images. Because layers are intermediate images, if you make a change to your Dockerfile, Docker will build only the layer that was changed and the ones after that. This is called layer caching.

[NB: Information Reff Link : https://docs.docker.com/v17.09/engine/userguide/storagedriver/imagesandcontainers/#images-and-layers]

1st step:

Install Docker form `https://docs.docker.com/docker-for-mac/install/` official website. If you have account in Docker, you can login or other end we can create new account in Docker. Before start using Docker we must login in Docker.

After install we can run the bellow command

1. docker -v we check docker version by this command.

2. docker ps we can get docker information using this command.

2nd Step: Image to Container (the Docker flow):

Create new image (Ubuntu or any other OS like ngnix etc) in docker run this command docker run -ti ubuntu:latest bash or If you want to create ngnix image we can run command docker run -ti ngnix:latest bash or we can specify the version docker run -ti ubuntu:14.04 bash. After finished we can see the screen as like

1.1

That mean our new Ubuntu 16.04 images was created.If we want to check of how many image exist in your Docker, we can run the command docker images

In my Docker have 3 images.
Kill the Docker image process using this command docker kill <IMAGE ID>
Start Docker by this command docker start <IMAGE ID>

If we want to delete or remove our image run the command. The command will work if Docker service is stop docker rmi <IMAGE ID>

If Docker service is start but we want to delete or remove the image we need run the command docker rmi — force <IMAGE ID>

3rd Step: Create Docker container to image

If we create Docker image from Docker container run docker ps -l here this command show last exited Docker.

In here we can see screen like

After that we can run this command docker commit <DOCKER ID>

Image was created if we want check created image run this command docker images

We can see the list of images.

Check our active Docker by this command docker container ls If we want to check in Docker all Container run this command docker container ls -a. After That we can see list of Docker Container

Check active Docker by this command docker container ls`

If we want to check in Docker all Container run this command docker container ls -a. After That you can see list of Docker Container

Now we discussed how to run Simple html file using Docker and pushed to Docker hub

First of all we create directory any where in our machine or pc. For my case I create a directory in Desktop the name docker_test.

In docker_test directory creates new file dockerfile and index.html this directory and

Add this code in dockerfile and advanced case you can set more configuration in Docker File for many other operations.

In this case we just run only html file using Docker that why we add simple code.

FROM php:7.2-cli
COPY . /Applications/MAMP/htdocs/

[in here we set your working directory]

if I work in mac os and also mamp apache server that’s why I set my working path And also add some html tag in index.html

Now We are ready to run and build simple html page using Docker.

So let’s start

Go to created directory in before where we have some file dockerfile` and index.html.You can see the list of file in our directory by this command ls

At last run the command to build project using docker

docker container run --name docker_test(Direcorty Name) -d -p 8880 -v $PWD:/user/share/nginx/html:ro -d ngionx

In browser run http://localhost:8880 we can see web page like bellow

If we terminate or kill the Docker Container Process So I want to run again Specific Docker Container Process

How can I run the Docker container process?

Let’s start , First we check list of all Docker container using this command docker ps -a bellow image we can see list of Docker Container

This image in Red line block status is up that mean this Container is currently active or running. Other Block status Exited that mean this Container is inactive.

So We are trying to start inactive container by this command docker run -it -d nginx /bin/bash or docker start <CONTAINER ID>

In details docker run -it -d <IMAGE NAME><COMMAND> or docker start <CONTAINER ID>

If we want to kill or terminate the process run the command docker stop <CONTAINER ID>

Above this command we can restart or stop our Docker Container.

--

--