09 Septembre
Commands to refresh :
docker ps
docker stop <CONTAINER ID>
docker rm <CONTAINER ID>
docker images
docker rmi <Image ID>
- 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.
- If there is no EXPOSE command then it will take default automatic port.
CMD ["apachectl","-D","FOREGROUND"]
- apachectl run the Deamon process in Foreground.
- 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"]
- 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.
- apache is project folder for Docker.
- Lets BUILD the file which we have created && dot . --> specifies where to build the image.
- 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
- Container and Image are different.
- 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
- 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
Install NGNIX
- 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.
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"]
docker build -t nginx_image .
- 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;"]
docker build -t nginx_image .
docker images
docker run -d --name ngix_container -p 8082:80 nginx_image
docker ps
Also try with below Docker File by placing a image file :
Questions :
- What is the difference between EXPOSE PORT in docker file and build container port ?
Important Points :
1.LTS - Long Term Support
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 ?
Solution :
docker system prune -a
2.Unable to load the apache server in localhost:8080
3.Deprecated Issue while building the image.
4.ERROR: failed to solve: LABEL must have two arguments
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"]
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
Discussion :
Usage: docker logs [OPTIONS] CONTAINER
docker logs dee
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;"]
Top comments (0)