This document covers the Docker basic commands which a basic HTML webpage is running in a container. The Docker container is created on Linode. Sign up for an account if you do not have one.
-
Search for docker in marketplace
-
Create a VM on Linode. Choose your image, region, Linode plan, set your root password and click Create Linode
-
On cmd, ssh into your VM via the command of ssh root@<your-VM-IP-address>. Enter your root password.
-
In your desired directory, create a src folder and a Dockerfile
-
Create a index.html file in your src folder. You can customise the html file to your liking.
-
Return to the Dockerfile and include the following commands
- FROM nginx:latest --> using the latest image of nginx for the container
- COPY src/index.html /usr/share/nginx/html --> copy the index.html in src folder to /usr/share/nginx/html
- EXPOSE 80 --> Docker container listen on port 80
- CMD ["nginx", "-g", "daemon off;"] --> Run nginx with daemon off when container starts up
-
Return to the directory where the Dockerfile is located and build the docker image with following command, where -t means tagging.
docker build -t <website-name> .
-
Enter the following command to check if the image has been created.
docker images
-
To run the docker container in detached mode and listen on port 8080 of host, enter the following
docker run -d -p 8080:80 <website-name>
-
To check if the container is running, enter the following
docker ps
-
Open the web browser and enter the following to see the webpage
http://<your-VM-IP-address>:8080
-
To stop the container, enter the following
docker stop <container ID>
-
To remove the container, enter the following
docker rm <container ID>
-
Before pushing the image into Docker hub, register an account and create a new repository, the name of repository has to be unique within your account
-
Enter the following on cmd to login your docker hub account and press ENTER. You will be prompted to enter password.
docker login --username=<your-username>
-
To push the docker image into your repository, enter
docker tag <image id> <your docker hub username>/<docker hub repo name>:latest
docker push <your docker hub username>/<docker hub repo name>:latest
-
Return to your docker hub account and the pushed image will be listed.