Docker Container Basics (Video)

This video shows how to create and run docker containers on a host machine (Ubuntu). It also illustrates how to version docker images and push to the docker hub repository.

1) Create Dockerfile

Add the following to the Dockerfile

FROM alpine
CMD ["echo", "Hello World version 1"]

 

2) Build Docker Image

Build the Docker image and confirm the built image.

$ docker build -t ksalawu/alpine-test:v1 .
$ docker images

 

The image is tagged using the -t option.

●  ksalawu is the Docker hub login for the repository to push the image to.
●  alpine-test is the name of the image
●  v1 is the tag representing the version number of the image
●  The ” .” indicates that the image should be built using the Dockerfile in the current directory

 

3) Run a Docker container on the local machine

Run a Docker container on the local machine to ensure it works properly before uploading to Docker Hub in next step.

$ docker run --rm --name test-container ksalawu/alpine-test:v1

 

The –rm flag removes the container after running and displaying the output.

The container is named test-container using the –name flag.

 

4) Push Docker Image to Docker Hub

$ docker push ksalawu/alpine-test:v1

 

 

5) Create a Script to Use in Dockerfile

Create a script file script.sh and make it executable.

Add the following content to the script to make it display a simple message when executed.

#! /bin/sh
echo Hello world version 2 from script!

 

 

6) Build a New Docker Image

Build a new Docker image and tag is as v2 to represent version 2. Confirm that the new image version v2 has been created.

$ docker build -t ksalawu/alpine-test:v2 .
$ docker images

 

The image is tagged using the -t option.

● ksalawu is the Docker hub login for the repository to push the image to.
●  alpine-test is the name of the image
●  v2 is the tag representing the new version number of the revised image
●  The ” .” indicates that the image should be built using the revised Dockerfile in the current directory

 

7) Run a Docker container for revised image on the local machine

Run a Docker container on the local machine to ensure it works properly before uploading to Docker Hub in next step.

$ docker run --rm --name test-container ksalawu/alpine-test:v2

The –rm flag removes the container after running and displaying the output.

The container is named test-container using the –name flag.

 

8) Push Docker Image to Docker Hub

$ docker push ksalawu/alpine-test:v2

We should see our docker image version on Docker Hub tagged as v1 and v2.

Leave a Reply

Your email address will not be published. Required fields are marked *