Managing Docker Images - Openshift Tutorial

Objectives:

  • Install git and Download a Demo Application
  • Create/Modify Docker file for the Application
  • Build the Image from Downloaded Application using Docker File
  • Run the Container from Local Image
  • Tag and Push the Image to Docker Hub
  • Remove the Image.

Pre-requisite

  • Local CentOS 7 VM with root access.
  • Docker-Engine pre-installed.

Sequence 1. Working with Containerized Application

  1. Pull sample app and clone an application from Github for testing

# git clone https://github.com/dockersamples/node-bulletin-board

# cd node-bulletin-board/bulletin-board-app

  1. Check the contents of Dockerfile in the bulletin board application.

# ls # cat Dockerfile

  1. Run the following command to build your bulletin board image:

# docker build --tag bulletinboard:1.0 . You’ll see Docker step through each instruction in your Dockerfile, building up your image as it goes.

  1. Run your image as a container by executing following command:

# docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0

  1. Visit your application in a browser at http://localhost:8000 or from your host machine visit http://10.10.0.200:8000. You should see your bulletin board as given in the screen shot.

  1. Share Your Image on Docker Hub

    . Use the docker command in your terminal to login

# docker login

  1. Check the image ID and create an additional tag for your image which should be pushed to Docker Hub.:

# docker image list REPOSITORY      TAG                 IMAGE ID            CREATED             SIZE bulletinboard   1.0                 bb538a7697d8        57 minutes ago      177 MB docker.io/node  current-slim        3aaf4acbaad7        13 hours ago        159 MB # docker tag bb538a7697d8 sangwan70/openshift:mybb   I’m using my Docker Hub username sangwan70 and I’m telling Docker to create a new tag with the name sangwan70/openshift:mybb

  1. Now use the docker push command to actually push the image to Docker Hub and make it available publicly, so that it can be used anywhere:

# docker push sangwan70/openshift:mybb The output on the command line should look like you can see in the following screenshot:

    1. Verify your Image on Docker Hub. Open the Tags tab to check the image pushed
    2. Clean up

      . Once you’re satisfied that your bulletin board container works correctly, you can delete it:

# docker rm --force bb # docker ps -a # docker images # docker rmi -f $(docker images -a -q) # yum clean all # docker system prune Watch the Lecture https://youtu.be/335j8HTxMVU