Sometimes, you don't want to use any docker images created by community, but created your own, for many reasons:
Whatever the reasons, let me guide you through the steps to create a new image from Ubuntu base.
We are going to take the existing Ubuntu 16.04 image and configure it from there. The current latest Ubuntu version at the time of writing is 16.04.
docker pull ubuntu:16.04
You should see somewhat the following:
16.04: Pulling from library/ubuntu
cad964aed91d: Pull complete
3a80a22fea63: Pull complete
50de990d7957: Pull complete
61e032b8f2cb: Pull complete
9f03ce1741bf: Pull complete
Digest: sha256:28d4c5234db8d5a634d5e621c363d900f8f241240ee0a6a978784c978fe9c737
Status: Downloaded newer image for ubuntu:16.04
Next, run the image in bash
docker run -i -t ubuntu:16.04 /bin/bash
Let's make sure we update the ubuntu image with the latest patches:
apt-get update
apt-get dist-upgrade
Next, you may go ahead to install whatever application you want and customise it. Once you're down, you can exit the container.
exit
Show the list of containers.
docker ps -a
It should look like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9dbd13c7a5ba ubuntu:16.04 "/bin/bash" 33 minutes ago Exited (0) 10 minutes ago compassionate_joliot
Take note of the Container ID. You need it to make a new image
Next, we need to commit this as a new image.
docker commit 9dbd13c7a5ba newimagename:v1
Be sure to use your container ID and name the container accordingly.
You will now see the new image you've created when you list the images.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
newimagename v1 29d9cae9fdfd 9 minutes ago 166 MB
ubuntu 16.04 c73a085dc378 2 days ago 127 MB
Now run the newly created docker image
docker run -i -t newimagename:v1 /bin/bash
Substitute the name of the image name with yours.
There you go. You are now running an instance of the newly created image. Exit from the image and list the containers to see your achievement.
exit
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
273f542f36e5 newimagename:v1 "/bin/bash" 14 seconds ago Exited (0) 10 seconds ago cranky_pike
9dbd13c7a5ba ubuntu:16.04 "/bin/bash" 43 minutes ago Exited (0) 19 minutes ago compassionate_joliot
You can see the new container is created from your new image.