1. create a new directory
mkdir whalesay
2. Inside the directory, create a dockerfile.
touch Dockerfile
3.Open it with your favorite text editor and add:
FROM docker/whalesay:latest
This first line of instruction, with the FROM keyword, tells Docker which image your image is based on. You are basing your new work on the existing image.
The next instruction that we will add will give the ability to our whale to tell a fortune. To accomplish this task, we will use the fortune package that is available in the Ubuntu repositories (remember that the whale image is based on an Ubuntu image). The fortunes program has a command that prints out wise sayings for our whale to say.
RUN apt -y update && apt -y install fortunes
Once the image has the software it needs, you instruct the software to run when the image is loaded. To do this we add the following instruction:
CMD /usr/games/fortune -a | cowsay
The above line tells the fortune program to send a randomly chosen quote to the cowsay program
And we are done! Now save the file and exit.
You can verify what you did by running "cat Dockerfile" so as that your Dockerfile looks like this:
cat Dockerfile
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
Now that everything (hopefully) looks good, its time to build our Docker Image (don’t forget the . period at the and of the command).:
docker build -t my-docker-whale .
You can verify that your Docker image is indeed stored on your computer with:
docker images
Then you may run your Docker image by typing the following:
docker run my-docker-whale
Once it runs, you will get something like the following image