DOCKER File create பண்ணனுமா ??? - Part 4
Published: 2023-09-15 03:07:48

> **09 Septembre**

## **<u>Commands to refresh :</u>**

```
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_**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bjo6culm25eqxc1tozs2.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ks4bfg7yf6mssgwohkf.png)

```
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"]
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3hnlge4cnyjst46z3c9f.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywp3bcpmvz5exjcxbrvg.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1u5t46epzewdtwjk3x5d.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ly6k7k64qtcpcsoyj2g3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dypnxozmo52u5m1a859c.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2da9wwo3mcddcc2amj5.png)

- 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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yfp2pcttekggu1llivbz.png)

- 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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zdgx69vbe0munucxtmzn.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnu7yanulodadagny8nk.png)

- 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
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lwn144ebbor9w240ke0.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2igrn9zeqjn7e6zyc7u6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yjohci958pczo9upebx8.png)

---

## Install NGNIX 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxqnfnvbme0g5l4q9d4k.png)

- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxofoxeao81zjt0la3kj.png)

```
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"]
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bl8g9nkuohkhc4jz5s9x.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yd1q1h5iazpsorzdev6e.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/apk4y5stfjwb03goho0z.png)

```
docker build -t nginx_image .
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8h57liutd688o05kspa.png)

- 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;"]

```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tyrt4y19ydyagugws1d7.png)

```
docker build -t nginx_image .
docker images
docker run -d --name ngix_container -p 8082:80 nginx_image
docker ps
```


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0fjpeik15erkivmcaa6.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mnkzx38p9tl698qups2.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gagp789vqw4a4o8i6mvb.png)


---


## **<u>Questions :</u>**

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

---


## **<u>Important Points :</u>**

1.**LTS - Long Term Support**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v610q7fo3s9u16xdt5gc.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0dzmjjqsph53o6v71ur.png)

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

---


## **<u>List of Error :</u>**


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

_<u>Discussion :</u>_

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f5anu5tmmgs7r0rj60fd.png)

_<u>Solution :</u>_

```
docker system prune -a
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/87kw7cxbtc74r78x3cp3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xaj666fu9mhrrksgyt2z.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cgv9hbqcpsjvu4pphjdp.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kkymz0qyckz5ver1c2l.png)

3.**Deprecated Issue while building the image.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tq20sko4vtxfboh3zig1.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nheenunwpq42rg2lkoq3.png)

```

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"]
```

_<u>Discussion :</u>_

Check the LABEL field by adding two arguments or parameters.

_<u>Solution :</u>_

Worked after adding two arguments.

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gk98f13tfjn2hjiii2xi.png)

_<u>Discussion :</u>_

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3lokyzpo0rq80zmum80q.png)

```
Usage:  docker logs [OPTIONS] CONTAINER
docker logs dee
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/20qm1qz0hyezp0elsfwx.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cznefs9i62ccwxjsrap4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gppzjljupngrsxbxbk1e.png)

_<u>Solution :</u>_

```
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;"]
```