Linux > Virtualization

Bulding and publishing a new docker image

(1/1)

aravindm:
1. create a new directory


--- Code: ---mkdir whalesay
--- End code ---

2. Inside the directory, create a dockerfile.


--- Code: ---touch Dockerfile
--- End code ---

3.Open it with your favorite text editor and add:


--- Code: ---FROM docker/whalesay:latest
--- End code ---

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: ---RUN apt -y update && apt -y install fortunes
--- End code ---

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: ---CMD /usr/games/fortune -a | cowsay
--- End code ---

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: ---cat Dockerfile

FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay
--- End code ---

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: ---docker build -t my-docker-whale .
--- End code ---

You can verify that your Docker image is indeed stored on your computer with:


--- Code: ---docker images
--- End code ---

Then you may run your Docker image by typing the following:


--- Code: ---docker run my-docker-whale
--- End code ---

Once it runs, you will get something like the following image



 ;)

Navigation

[0] Message Index

Go to full version