This blog post does contain the tasks to create a Docker image and upload the image to dockerhub and clean up the image and container on the local machine.
Upload the image
1. Create a local Docker image using docker build
- Dockerhub account name: tsuedbroecker
- Dockerhub repository name: cns-workshop-tools
- Tag: v4
- Docker image name with tag: tsuedbroecker/cns-workshop-tools:v4
docker build -t "tsuedbroecker/cns-workshop-tools:v4" .
2. Run the Docker image as a container
docker run with the interactive terminal mode parameter -it to verify the content of your Docker image you just created.
For example: Check different CLI versions like the IBM Cloud CLI inside the running container of your image.
Container name: demo
Docker image name: tsuedbroecker/cns-workshop-tools:v4
docker run -it --name demo "tsuedbroecker/cns-workshop-tools:v4" /bin/bash
Here an example to verify a installed IBM Cloud CLI:
root@dbe62179b56a:/tmp# ibmcloud version ibmcloud version 1.2.3+3577aee6-2020-09-25T14:34:09+00:00 root@dbe62179b56a:/tmp#
3. Push the Docker image to Dockerhub
docker push tsuedbroecker/cns-workshop-tools:v4
4. Verify at the image was uploaded to Dockerhub
1. Show the existing running Docker containers
docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dbe62179b56a tsuedbroecker/cns-workshop-tools:v4 "/bin/bash" 15 minutes ago Exited (127) 12 minutes ago demo
Note: Stop all running container docker kill $(docker ps -a -q)
2. Delete a running container
Copy the CONTAINER ID and delete the running container with docker rm
docker rm dbe62179b56a
Note: Remove all running container docker rm $(docker ps -a -q)
3. List the existing container images
docker image list
REPOSITORY TAG IMAGE ID CREATED SIZE tsuedbroecker/cns-workshop-tools v4 ff088202f1dc 31 minutes ago 925MB ubuntu latest d70eaf7277ea 5 days ago 72.9MB c18da3b7a242 5 months ago 206MB
4. Remove the container image
Copy the image repository name and tag and delete the image with docker image rm.
- Image name: tsuedbroecker/cns-workshop-tools
- Tag: v4
docker image rm tsuedbroecker/cns-workshop-tools:v4
Note: You can delete all images with
docker image prune -a
I hope this was useful for you and let’s see what’s next?