Dockerlab 104 Creating Docker image with Dockerfile

Step 0 : Create docker hub account. https://hub.docker.com

Step 1 : Open Play with Docker or login in below with your docker hub account.

Step 2 : Click on start

Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE

Step 4 : Click in terminal and press enter.

Step 5 : vi Dockerfile

FROM ubuntu

RUN apt-get update

RUN apt-get install figlet

CMD ["figlet", "hello docker"]

  • Create a Dcokerfile using vi

Step 6 : docker image build -t imageformfile:0.1 .

  • docker image build command create docker image

  • with "imagefromfile" as name

  • and 0.1 as tag

  • do not miss " . " at the end

Step 7 : docker container run imageformfile:0.1

  • docker container run spin up a new container with image imageformfile:0.1

  • It will print hello docker

Step 8 : docker image ls

  • list image on local system

Step 9 : docker image history <image ID>

  • docker images are built in layers

  • a layer for every command we have in Dockerfile

Step 10 : vi Dockerfile

CMD ["figlet", "hello docker 0.2"]

  • modify CMD in Dockerfile

Step 11 : docker image build -t imageformfile:0.2 .

  • build a new image with 0.2 tag

  • docker will reuse exiting layers and update only layer which is required

Step 12 : docker container run imageformfile:0.2

  • output will be update to hello docker 0.2