Docker Explore Part 2 – Pull, Ship and Run


Once you have docker installed in Ubuntu, you can start to pull image from Docker Hub and run it on your local system. Also noticed that, there is hubs that exist host by 3rd party. One of them is https://c.163.com/hub#/m/home/ which hosted by NetEase, due to the Chinese slow internet to Docker Hub.

Anyway, Docker Hub (https://hub.docker.com/) is always the site you want to use if possible.

Before we start the first pull, we can run the following command to check whether there is any image has been pulled previously. If this is the first time you run the command. You should receive the result as follow.

root@ip-172-31-11-57:/home/ubuntu# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE

Let’s do our first pull. The image I want to pull is hello-world. You can find it from Docker Hub by using the browser.

root@ip-172-31-11-57:/home/ubuntu# docker pull hello-world
 

Then run the docker images again, you will see hello world.

root@ip-172-31-11-57:/home/ubuntu# docker images
REPOSITORY TAG IMAGE ID CREATED
hello-world latest 48b5124b2768 4 months ago 1.84 kB

Simply run the hello-world to see the result.

root@ip-172-31-11-57:/home/ubuntu# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

This is just something that running from the frontend,  you only see the message once you run the command. There are many images that can handle back-end service as well. Such as Nginx.

So firstly, pull the Nginx from Docker Hub.

root@ip-172-31-11-57:/home/ubuntu# docker pull ngnix

Instead of run it from the frontend, we choose to run it from background. Notice that, you can run it from frontend, then you need to open another ssh connection, which is not recommanded.

root@ip-172-31-11-57:/home/ubuntu# docker run -d nginx
4bc53d0d27386a5d17aaa1fa18228d0573f508d75467e26811b6544453108b48

It returns the container ID. use –help to see more other options for docker run. To check what docker service is running use ps for docker.

root@ip-172-31-11-57:/home/ubuntu# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bc53d0d2738 nginx "nginx -g 'daemon off" About a minute ago Up About a minute 80/tcp dreamy_bhabha

We know that after pull the image and run it. It actually copies all the files that required to the container. So you should be able to change directory to the container as follows.

root@ip-172-31-11-57:/home/ubuntu# docker exec -it 4bc bash
root@4bc53d0d2738:/# ls
bin boot dev etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var

As you can see once to change directory to the container ID. we can see all the file directories like a Linux that holding a Nginx service.