Building Container Images Using Dockerfiles
Sami Ullah Saleem
Posted on August 16, 2023
1- Create Dockerfile
~ vi Dockerfile
FROM httpd:2.4
RUN apt update -y && apt autoremove
- Dockerfile always start from FROM keyword and after it we tell the image name like we are telling here httpd of which we want to create our container.
- RUN whatever we are going to write after RUN it will be run in our container.
~ docker build -t wigetfactory .
- Here you can see that we are creating our image from our Dockerfile and giving it a name which is wigetfactory
2- Let's update our Dockerfile and put our website content in it.
FROM httpd:2.4
RUN apt update -y && apt autoremove
rm -f /usr/local/apache2/htdocs/
WORKDIR /usr/local/apache2/htdocs/
COPY ./web .
Here you can see that I am changing my container work directory using *WORKDIR * command and then copy my website content from my host directory to the container location which is htdocs.
Let's run our Dockerfile again.
~ docker build -t widgetfactory:0.3 .
Here will be the output of it
- Now run container using the image.
docker run --name weebproject -d -p 80:80 widgetfactory:0.3
Follow me for more content
💖 💪 🙅 🚩
Sami Ullah Saleem
Posted on August 16, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.