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
Top comments (3)
How about if I do not use Dockerfile?
Whatever you have written in the docker file. You have to do from your host terminal. But commands will be different.
You can read my this article
dev.to/aws-builders/hosting-site-o...