Friday, May 24, 2019

Docker - getting started (very basics)


Docker-Overview

Docker makes much easier to deploy applications. It helps to resolve one main problem - “works in my machine problem”. 

Getting started
  • Download docker from here for your OS: 
  • Install the docker DMG if Mac.
  • Login to docker once it is installed. 
  • Open terminal and execute the following: 
    • Docker -version
    • Docker run hello-world
    • Docker run —name deiveehello hello-world
    • Docker run -it —name mylinuc-container ubuntu bash
For a hands on video - click here

——————————————————————
Some basic docker commands
——————————————————————

Docker images // lists all images
Docker ps // lists all process
Docker run —help

———————————————————————
Running a docker using simple ubuntu image
———————————————————————

docker ps -a -f status=exited -q
docker rm $(docker ps -a -f status=exited -q)
docker run -it --name my-linuc-container-1 ubuntu bash


docker run -it --name my-linux-container1 --rm -v /Users/deiveehannallazhagappan/Documents/volumes/project1:/my-data ubuntu bash
Cd my-data
Touch aa.txt
Ls

———————————————————————
Creating image from a local docker file.
———————————————————————

  • Create a docker file with the following content.
FROM ubuntu
CMD echo "Hello Deivee"
  • Run the following command. 

docker $docker build -t deivee-tracker-image .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM ubuntu
 ---> f975c5035748
Step 2/2 : CMD echo "Hello Deivee"
 ---> Running in 10c68c4eb454
Removing intermediate container 10c68c4eb454
 ---> b235e94e39b4
Successfully built b235e94e39b4
Successfully tagged deivee-tracker-image:latest

docker $docker images
REPOSITORY             TAG                 IMAGE ID            CREATED              SIZE
deivee-tracker-image   latest              b235e94e39b4        About a minute ago   112MB
ubuntu                 latest              f975c5035748        4 weeks ago          112MB
hello-world            latest              f2a91732366c        4 months ago         1.85kB

———————————————————————
Run the docker image
———————————————————————
docker $docker run deivee-tracker-image
Hello Deivee
docker $docker ps -a
CONTAINER ID        IMAGE                  COMMAND                   CREATED             STATUS                      PORTS               NAMES
9a65c141ec46        deivee-tracker-image   "/bin/sh -c 'echo \"H…"   5 seconds ago       Exited (0) 4 seconds ago                        optimistic_stonebraker
0e922f16f866        ubuntu                 "bash"                    12 minutes ago      Exited (0) 11 minutes ago                       tracker
be1311055d15        ubuntu                 "bash"                    23 minutes ago      Created                                         my-linux-container
77447d4d6c02        hello-world            "--name deiveehello"      12 hours ago        Created                                         elastic_wozniak

For a more hands on video on getting started with Docker, click here.
https://www.youtube.com/watch?v=hfL0USkCmZ0&t=305s


No comments:

Post a Comment