Intoduction to the Dockerfile

Intoduction to the Dockerfile for beginner

source image : deploybot.com

Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. source:

create Dockerfile

vim Dockerfile

The content Dockerfile

FROM docker/whalesay:latestRUN apt -y update && apt install -y fortunesCMD /usr/games/fortune -a | cowsay

The FROM instruction initializes a new build stage and sets the for subsequent instructions. As such, a valid Dockerfile must start with a FROM instruction. The image can be any valid image – it is especially easy to start by pulling an image from the .

RUN has 2 forms:

  • RUN <command> (shell form, the command is run in a shell, which by default is /bin/sh -c on Linux or cmd /S /C on Windows)
  • RUN ["executable", "param1", "param2"] (exec form)

The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.

The CMD instruction has three forms:

  • CMD ["executable","param1","param2"] (exec form, this is the preferred form)
  • CMD ["param1","param2"] (as default parameters to ENTRYPOINT)
  • CMD command param1 param2 (shell form)

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

Build the Dockerfile

sudo docker build -t docker-whale .

see docker image

sudo docker image ls
docker images

Then run image docker-whale

sudo docker run docker-whale
run image docker-whale

Reference :

This is my little notes based my experiment and my learning. Keep learning and keep calm.

This is my little notes based my experiment and my learning. Keep learning and keep calm.