DOCKER File create பண்ணனுமா ??? - Part 4

technonotes-hacker - Sep 15 '23 - - Dev Community

09 Septembre

Commands to refresh :

docker ps
docker stop <CONTAINER ID>
docker rm <CONTAINER ID>
docker images 
docker rmi <Image ID>
Enter fullscreen mode Exit fullscreen mode
  • File name is very important here , "D" should be capital don't forget.
  • NO extension should be given for the docker file.
  • There are two commands - Docker commands & Docker File commands
  • DOCKER FILE COMMANDS SHOULD BE ALWAYS IN CAPITAL LETTER.

Image description

  • If there is no EXPOSE command then it will take default automatic port.

Image description

CMD ["apachectl","-D","FOREGROUND"]
- apachectl run the Deamon process in Foreground.
Enter fullscreen mode Exit fullscreen mode
  • CMD can be only 1 in each Docker file other File commands can be 'n' number of times.
FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install apache2 -y
RUN apt install apache2-utils -y
RUN apt clean
COPY index.html /var/www/html/
EXPOSE 80
CMD ["apachectl","-D","FOREGROUND"]
Enter fullscreen mode Exit fullscreen mode

Image description

  • Now create a index.html ? why we need to create ? Any Idea !! Bcouz we gave a command to move the index file in the Docker File.

Image description

  • apache is project folder for Docker.
  • Lets BUILD the file which we have created && dot . --> specifies where to build the image.

Image description

Image description

Image description

Image description

  • Image build is completed && Out of this image we need to run the container.
cd apache/
ls --> Dockerfile  index.html
docker build -t apache_demo .
docker images
docker run -d --name apache_demo_container -p 8080:81 apache_demo
docker ps
docker ps -a
Enter fullscreen mode Exit fullscreen mode
  • Container and Image are different.

Image description

  • Encountered an issue which is explained in Error list 2 , kindly check . So the port got modified.
docker run -d --name apache_demo_container_2 -p 8081:80 apache_demo
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

  • Now login to the container and explore.
docker ps -a
docker exec -it <container ID/ NAMES> /bin/bash 
eg., docker exec -it 83 /bin/bash
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description


Install NGNIX

Image description

  • Nginx is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache.
  • The software was created by Igor Sysoev and publicly released in 2004.
  • Nginx is free and open-source software, released under the terms of the 2-clause BSD license.

Image description

FROM ubuntu:20.04
LABEL sathishpy1808
#ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install nginx -y
RUN apt clean
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx","-g","daemon off"]
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

docker build -t nginx_image .
Enter fullscreen mode Exit fullscreen mode

Image description

  • Changes to a field : LABEL also after daemon add a ";" without fail.

FROM ubuntu:20.04
LABEL sathishpy1808 created the Docker File**
#ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install nginx -y
RUN apt clean
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]

Enter fullscreen mode Exit fullscreen mode

Image description

docker build -t nginx_image .
docker images
docker run -d --name ngix_container -p 8082:80 nginx_image
docker ps
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Also try with below Docker File by placing a image file :

Image description


Questions :

  1. What is the difference between EXPOSE PORT in docker file and build container port ?

Important Points :

1.LTS - Long Term Support

Image description

Image description

2.Delete a line in vim or vi mode - Use "Esc" then "dd"


List of Error :

1.Error response from daemon: conflict: unable to delete 961e044d9228 (must be forced) - image is being used by stopped

Discussion :

  • there is no container running but why unable to delete the image ?

Image description

Solution :

docker system prune -a
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

2.Unable to load the apache server in localhost:8080

Image description

Image description

3.Deprecated Issue while building the image.

Image description

4.ERROR: failed to solve: LABEL must have two arguments

Image description


FROM ubuntu:20.04
LABEL sathishpy1808
#ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install nginx -y
RUN apt clean
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx","-g","daemon off"]
Enter fullscreen mode Exit fullscreen mode

Discussion :

Check the LABEL field by adding two arguments or parameters.

Solution :

Worked after adding two arguments.

5.Status : Exited (1) About a minute ago

Image description

Discussion :

Image description

Usage:  docker logs [OPTIONS] CONTAINER
docker logs dee
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Solution :

FROM ubuntu:20.04
LABEL sathishpy1808 created the Docker File
#ENV DEBIAN_FRONTEND=noninteractive
RUN apt update
RUN apt install nginx -y
RUN apt clean
COPY index.html /var/www/html/
EXPOSE 80
CMD ["nginx","-g","daemon off;"]
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player