Giter Club home page Giter Club logo

docker-basics's Introduction

Docker Basics

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

    image

  • Create a VM on Linode. Choose your image, region, Linode plan, set your root password and click Create Linode

    image

  • 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

    image

  • Create a index.html file in your src folder. You can customise the html file to your liking.

    image

  • 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

    image

  • 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

    image

  • 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.

    image

docker-basics's People

Contributors

pohwj avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.