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. Using “docker build” users can create an automated build that executes several command-line instructions in succession.
In the following steps, you will create a docker file, to use in building an image and then run the new image on your local machine
On MacOS
mkdir mydockerbuild; cd mydockerbuild
On Windows
c:\md mydockerbuild
c:\cd mydockerbuild
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
For this exercise, we used the docker/whalesay:latest image, which is based on Ubuntu Liunx distribution.
The RUN statement will execute the command and record changes to the file system. It will NOT record the state of processes or start daemons.
The CMD statement defines the default command to execute when the container is created. This command runs fortune -a and sends its output to the cowsay command.
docker build -t docker-whale .
docker images
The output should look something like this
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest c2c3152907b5 4 minutes ago 275.1 MB
docker/whalesay latest fb434121fc77 4 hours ago 247 MB
hello-world latest 91c95931e552 5 weeks ago 910 B
docker run docker-whale
The output should look something like this
--------------------------------------
< You will be successful in your work. >
--------------------------------------
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\______/