Sample webpage with NGINX to play around with docker!
162
Install Docker from the official website: https://www.docker.com/
After successful installation of Docker, you can try out some of the basic commands from the terminal:
docker run -it -p 80:80 nginx
Here the -it is for interactive, -p is for port, 80:80 are the local and nginx ports, nginx is the image name.
If the image is not available in local system, docker will pull it from docker hub automatically.docker pull nginx
[docker pull docker container run -d -p 8080:80 --name myFirstContainerNginx nginx
[-d is for detach, —name is to give container a name]The only difference between the first and second approach is that -it and -d.
docker imagesdocker image rm <IMAGE_ID> (3 characters of the ID field will work here!)docker container ls [docker ps also works!]docker container ls -a [docker ps -a also works!]docker container rm <CONTAINER_ID> (3 characters from the ID field will work here!)docker container run -d -p 3306:3306 --name mysql_container --env MYSQL_ROOT_PASSWORD=12345 mysqldocker container stop <container_name>
This command will stop the container. Even though it is not running, it is still present on the local system. You can use docker ps -a command to check the list of all the containers.docker container rm <container_name> -f
We have to use -f [force] flag since the docker is currently running.docker container exec -it <container_name> bash
This command will take you to the bash inside of the container, where you can “ls” and check the folders.exit.Check out the GIST that has all the basic commands that we will use in docker.
-v flag : map a local system path to the file path on the container.
docker container run -d -p 8080:80 -v $(pwd):/usr/share/nginx/html --name nginx-website nginx
Bind mount is created from local file system to inside the container through the above command. This means we have access to the webroot inside the container via the $(pwd) directory.
If we create a file in the $(pwd), say index.html and update it with an "h1" tag.
Now, if we go back to localhost:8080, we can see “Hello World!” being displayed instead of the default Nginx webpage. This is because now we have access to the webfoot of nginx directory in the docker “nginx-website”.
Create a new file about.html with a different "h1" tag.
Now, if we access localhost:8080/about.html, we can see the message “About page!!” being displayed.
FROM nginx:latest
WORKDIR /usr/share/nginx/html/
COPY . .
docker image build -t sydrawat/ngnix-website .
This command will build the image based on the Dockerfile that we have created in the local repository. To push it to docker hub from our profile, we need to use the -t flag and provide our /. This will push it to the docker hub after it is successfully built. The ‘.’ at the end of the command refers to the docker file that is present in the $(pwd).docker container run -d -p 8082:80 sydrawat/nginx-website => this will create the docker container. You can access the localhost:8082 to check if it is working. Also check localhost:8082/about.html.docker push sydrawat/nginx-websitedocker login to authenticate.[Check out the vide from Traversy Media for a video description of this document]
Content type
Image
Digest
Size
42.7 MB
Last updated
about 7 years ago
docker pull sydrawat/nginx-website