Docker Hub

Sharing Docker images is made easy by Docker Hub. Anybody can create an account to Docker Hub to distribute images that can be deployed on other systems or by other users.

For this example, let us use an open source project from github. The TodoMVC using Nodejs, Vue, and Nuxt should be a great example. It is a demo application using JavaScript on the server and client.

Lets clone the project so that we have it on our computer. Cloning the git repository can be done with the following command:

git clone https://github.com/nuxt/todomvc.git

This will download the project in a directory called todomvc.

By default the project does not provide a Dockerfile. We will need to create one. An example could be:

This Dockerfile will use a node image to provide the JavaScript runtime on the server. It will also install all dependencies using the npm package manager. Finally it will start the application using the npm start command.

Lets build it using the command

docker build -t todomvc .

You can test the container using the command

docker run -it -p 80:3000 todomvc

When everything works well, you could share the image using Docker Hub. You will need to create an account to be able to push (upload) an image and distribute it to other systems or developers.

When you have an account, you can log in to Docker Hub using the command

docker login

Before we can push the container we need to 'tag' it with a name. This can be done using the command

docker tag todomvc YOUR-USER-ID/todomvc

Don't forget to replace YOUR-USER-ID with your Docker Hub user id.

Now you are ready to push the image to Docker Hub using the command

docker push YOUR-USER-ID/todomvc

You can now go to your Docker Hub and see your newly pushed image at https://hub.docker.com/

The image is now available to anybody and a container be created from it and run using the command

docker run -it -p 80:3000 YOUR-USER-ID/todomvc

You should now be able to visit the webpage at http://192.168.99.100

Last updated