Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Bulding and publishing a new docker image  (Read 16456 times)

0 Members and 1 Guest are viewing this topic.

aravindm

  • Guest
Bulding and publishing a new docker image
« on: July 14, 2018, 12:38:33 pm »
1. create a new directory

Code: [Select]
mkdir whalesay
2. Inside the directory, create a dockerfile.

Code: [Select]
touch Dockerfile
3.Open it with your favorite text editor and add:

Code: [Select]
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.

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
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).:

Code: [Select]
docker build -t my-docker-whale .
You can verify that your Docker image is indeed stored on your computer with:

Code: [Select]
docker images
Then you may run your Docker image by typing the following:

Code: [Select]
docker run my-docker-whale
Once it runs, you will get something like the following image



 ;)