Project Introduction
This project demonstrates how to containerize a website using Docker and deploy it. We will be hosting this website on Azure. By leveraging Docker's containerization capabilities, this project showcases a streamlined process for building, shipping, and running CSS templates. This project includes a Dockerfile, a build image, and a public Docker repository for easy access. Without wasting much time, let's dive in...
Step 1: Let's create a Docker registry
- Go to your browser and search for Docker Hub
- Click on sign up and sign up
Step 2: Create a public Docker repository
- Log in to the Docker Hub
- Locate the repository on your left
Step 3: Create a Virtual Machine and connect it
- I created an Azure virtual machine for this project.
Step 4:
- After connecting your virtual machine, type sudo apt update
- Mkdir Docker ( making a directory with the name Docker)
- Type ls
- Type cd Docker
Step 5: Creating a website
- Go to your browser and search for free CSS templates
- Select the one you like
- Right-click on it and copy the link ( the link should end with .zip)
- In case you didn't see .zip at the end, download it. After downloading it, click on your download history and copy the link there.
- Go to your terminal, type wget, and paste the link
- Type ls (to see it)
- Type du -sh to see (the size)
- Type sudo apt install unzip -y ( to install unzip so that we can unzip the zipped image)
- After installing the unzip, type unzip and paste your image name
- Type ls ( you will see both the zipped and unzipped files)
Step 6: Dockerfile, and build our image
- Type nano dockerfile
- Once it opens, type FROM ubuntu:latest
- RUN apt-get update
- RUN apt-get install -y nginx
- RUN rm -rf /var/www/html
- COPY . /var/www/html
- EXPOSE 80
- CMD ["nginx", "-g", "daemon off;"]
- Press control x, press y to save and exit
- Once you exit, type cat dockerfile
- Type sudo cp dockerfile and the name of your image/
- Type cd and the name of your image
- Type ls
- Type ls -la
Step 6: Let's build our image
- Type sudo docker build -t your image name . (The dot is telling the location of the file)
- Run a container with the image by typing sudo docker run -d -p 80:80 your image name
- Type sudo docker ps
- Go and copy your virtual machine public IP, go to your browser and paste it with:80
Step 7: Let's push our image to our Docker repository
- Type sudo docker tag your image name:latest the name of your repository:vi
- Type sudo docker images
- Type sudo docker login -u your Docker Hub registry username
- Go to your Docker Hub registry, click on your username icon on the right, and click settings. Click on personal token and generate a token
- Copy the token, go back to your terminal, and paste it where you see password
- Type sudo docker tag your image name your repository name:vi
- Then type sudo docker push your docker repository name:vi
- Final result
Top comments (2)
Deploying a site with Docker feels like wizardry the first time you do it 🪄. Great work!
Thank you Anik for your wonderful thought on this project.