#26 Docker File

Table of contents

No heading

No headings in the article.

Lecture-9 Dockerfile Part-1

  • A Dockerfile is a text document that contains all the commands you would normally execute manually to build a Docker image. Docker can build images automatically by reading the instructions from a Docker file. In a Dockerfile, an ENTRYPOINT is an optional definition for the first part of the command to be run.

Create a docker file :

Build a Dockerfile :

Build an image from the current path and will search for the file from the current path.

-t is a tag

Build an image from the current path with the given file name.

Lecture-10 Dockerfile Part- 2

Package Installation on single command.

Docker file layer architecture:

FROM centos: In the first layer creates a container from the base image i.e. centos and delete that container.

2nd layer: run the touch command by using the previous image and created the container and image.After that deleted that container.

Creating a build using cache. and new layer commands will create a container that will create an image and delete that container.

If u append the data from the beginning/in the middle layer will start from that path.

Lecture-11 Dockerfile Part -3

Lable define on docker file.

Define environment variable.

Use case:

Define Environment variable.

Instead of login into the root, log in from the mentioned user.

Define the working path:

Copy CMD:

Difference between ADD and COPY commands:

COPY command will copy the tar.gz file to mentioned location.

Image build :

Container build:

Add command extracts the tra.gz file and keep the content in the mentioned location.

build img:

Build container:

The COPY command will copy the whole link in the mentioned path instead ADD command will copy the content of that link.

got failed due to which is asking for the source. Instead, ADD command will copy the content work as wget.

CMD command: When an image is built and deployed in the container First which command needs to be run? which is done by the CMD command.

Lecture-12 Dockerfile Part- 4

PORT mapping:

If you want to expose port/to do the ssh you need to define it in the docker file.

Instaall ssh package.

Deamon start :

Deamon restart.

Port expose by EXPOSE 22

Image build :

Image deployment :

Done SSH from host machine:

Do the access from outside/remote/another laptop machine for that required port mapping:

mapping to host port: container port.

From outside if you want to connect to eth0 IP where AWS allows public IP in IGW which translates to private ip and that private IP translates to container IP {i.e eth0}which is always private. Hence access the container from the outside.

Lecture-13 Dockerfile Part-5

Container IP

You can access from outside by using public IP who translates to private IP which is connected to the container IP.

Lecture-14 Dockerfile Part-6

Custom name for the docker files.

Need to provide the proper path to build the image

Without creating a docker file you can build an image as well.

Build a docker file from the remote machine:

No need to write an image keyword without that also the image will get built.