Here’s a step-by-step guide with the detailed commands to achieve each step in Kali Linux:
- Install Docker
First, make sure Docker is installed on your Kali Linux system. Run these commands:
sudo apt update
sudo apt install docker.ioAfter installing Docker, start and enable the Docker service:
sudo systemctl start docker
sudo systemctl enable dockerTo verify if Docker is installed correctly, run:
docker --version- Create a Container
To create a container from an image (e.g., ubuntu), use the following command:
docker run -it --name my_container ubuntu /bin/bashThis creates a container called my_container and starts a bash shell in it.
- Access Your Container
You can access the container you just created by using:
docker exec -it my_container /bin/bashThis will drop you into the shell of your running container.
- Clone Your Code into Container from GitHub
Inside the container shell, make sure git is installed, and clone your repository from GitHub:
apt update
apt install git
git clone https://github.com/your_username/your_repo.gitMake sure to replace your_username and your_repo with the actual repository details.
- Create an Image from Container
Once you’ve cloned your code into the container, exit the container shell and create an image from the container:
docker commit my_container my_dockerhub_username/my_image_nameThis will create an image with your code inside it. Replace my_dockerhub_username and my_image_name as per your requirement.
- Push to Docker Hub
First, log in to Docker Hub:
docker loginThen, push the image to your Docker Hub account:
docker push my_dockerhub_username/my_image_name- Delete Container and Local Images
To delete the container:
docker rm -f my_containerTo delete the local image:
docker rmi my_dockerhub_username/my_image_name- Pull Your Image from Docker Hub
To pull your image back from Docker Hub:
docker pull my_dockerhub_username/my_image_name- Create a Container and Start It on Port 80:80
To create and run a container from the pulled image and expose it on port 80:80, use:
docker run -d -p 80:80 my_dockerhub_username/my_image_nameThis will map your host’s port 80 to the container’s port 80 and run the container in detached mode (-d).
- Access Your Website
Now, open a browser and access your website by going to:
http://localhost
If you’re accessing it remotely, replace localhost with your server’s IP address.