Start by creating a Docker Hub account if you don’t already have one. You will use it to log in later in this exercise.
How to search images on DockerHub ?
$ docker search alpine
$ docker image pull alpine
$ docker image ls
$ docker image ls --digests
$ docker image inspect alpine
$ docker container run -it --name myfirstimage alpine sh
$ echo "My first docker image" > /opt/hello.txt
N.B: Detach from the container using CTRL-p CTRL-q
$ docker container diff myfirstimage
You can see the change in /opt
Now, run the commit command to commit your myfirstimage, associate it with a new image named docker-hub-username/alpine:v1.1, where v1.1 is the image tag and docker-hub-username is your Docker Hub username.
$ docker container commit myfirstimage docker-hub-username/alpine:v1.1
Lets start a container from the new image and verify the existence and contents of /opt
$ docker container run -it docker-hub-username/alpine:v1.1 sh
$ docker login
After login is succeeded the username would be reflected in the docker output.
$ docker info
$ docker image push docker-hub-username/alpine:v1.1
Now you know how to build a docker image. Here is a task for you. Run a Simple Nginx Server based on an already existing public Docker Hub image.
<h1> Hello This is my First Container </h1>
With what we have learned so far, the container should be up and running, the website should be responding from the inside of the Container, but external access should be failing. We will look into why it is failing to be accessed externally in the next section, Docker Networking