It contains all commands for building an image in text format.

The Dockerfile, a standardised, executable component, contains the OS libraries and dependencies needed to run the application source code that is not OS-dependent.

The Dockerfile uses Domain Specific Language (DSL) and comprises directives for creating a Docker image. When developing your application, it is essential to generate a Dockerfile, as the Docker daemon executes all instructions sequentially from top to bottom.

 

Dockerfile commands/Instructions

  • FROM : Denotes the foundational image (operating system), which is the initial command executed prior to any further commands. 
    FROM ubuntu:19.04
  • COPY: used to copy the file/folders to the image while building the image.  
    COPY <Source>   <Destination>  
  • ADD: The ADD command can be employed to download files from remote HTTP/HTTPS destinations during the image creation process. 
    ADD <URL>  
  • RUN: used to execute scripts and commands. The RUN commands or instructions will be executed as you construct an image on top of the previous layers (Image).
    RUN < Command + ARGS>
  • CMD: initiate the process within the container, but it is capable of being overridden.
    CMD [command + args]
  • ENTRYPOINT: configures a container that will serve as an executable. Upon initiating the Docker container, the ENTRYPOINT command or script is executed.
    It is incapable of being overridden.The sole distinction between CMD and ENTRYPOINT is that CMD can be overridden, while ENTRYPOINT cannot.
    ENTRYPOINT [command + args]
  • MAINTAINER: lets us identify the Dockerfile author/owner and establish our own image author/owner.
    MAINTAINER <NAME>

 

Stages of Creating Docker Image from Dockerfile

  • Make a Dockerfile.
  • Add Dockerfile instructions.
  • Image creation using Dockerfile.
  • Run the image to containerise (create a container)

 

Build a Web Server Docker File?
first Installed docker software in your respective operating system.

Step 1: Building our Docker file with vim is the first step. 

vim Dockerfile
Name of the file has to be “Dockerfile”

Write this to the Docker file.

FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
EXPOSE 80
CMD ["apache2ctl","-D","FOREGROUND"]

Describe the above commands

  • Ubuntu is our server start image.
  • The second line sets a non-interactive environment.
  • The final line updates all Ubuntu packages with apt-get update.
  • The fourth line installs apache2 on our image.
  • The fifth line installs all Apache utility packages.
  • The sixth line of apt-get clean removes all unneeded files.
  • The seventh line exposes Apache port 80 in the container using EXPOSE.
  • The final command runs apache2 in the background.

 

Step 2: Build the docker file with docker build. 

Docker build "mywebserver"

-t tags the image with mywebserver as the tag. After building the image, a message will print that must be built. 

 

Step 3: After building the web server file, we use docker run to create a container from the image

Docker run -d -p 80:80 tag_name 

d: This option allows the container to execute in detached mode, in the background. -p maps our port number to 5000 localhost port numbers.

 

Can Also configure docker Desktop

Open docker setup, open Settings > Advance 

The Resources tab allows you to configure CPU, memory, disk, proxies, network, and other resources.

The Resource allocation options in the Advanced tab are only available in Hyper-V mode, because Windows manages the resources in WSL 2 mode and Windows container mode. In WSL 2 mode, you can configure limits on the memory, CPU, and swap size allocated to the WSL 2 utility VM. You are using the WSL 2 backend, so resource limits are managed by Windows.

Memory: 4 GB

CPU: 2


Related Question