0% found this document useful (0 votes)
18 views

Lab5.2.ImageOperationswithDocker

This document provides a detailed guide on performing image operations using Docker, including searching for images, pulling the official nginx and alpine images, and managing image tags. It also covers how to push images to Docker Hub, inspect image details, and remove images from the local repository. The document illustrates commands and outputs for various Docker operations to help users understand image management effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lab5.2.ImageOperationswithDocker

This document provides a detailed guide on performing image operations using Docker, including searching for images, pulling the official nginx and alpine images, and managing image tags. It also covers how to push images to Docker Hub, inspect image details, and remove images from the local repository. The document illustrates commands and outputs for various Docker operations to help users understand image management effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LFS253_12.30.

2021 1

Lab 5.2. Image Operations with Docker


Since we have configured Docker to run as non-root, we can now run docker commands as the student
user. Let’s search the Docker Hub registry for container images, using nginx as a search term. Many
search results will be displayed, but only one “official” image, which we will use in subsequent steps:

student@ubuntu:~$ docker search nginx

NAME DESCRIPTION
STARS OFFICIAL AUTOMATED
nginx Official build of Nginx.
15303 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker
con… 2059 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable
of… 815 [OK]
jc21/nginx-proxy-manager Docker container for managing Nginx proxy
ho… 232
linuxserver/nginx An Nginx container, brought to you by
LinuxS… 150
tiangolo/nginx-rtmp Docker image with Nginx using the
nginx-rtmp… 138 [OK]
jlesage/nginx-proxy-manager Docker container for Nginx Proxy Manager
131 [OK]
alfg/nginx-rtmp NGINX, nginx-rtmp-module and FFmpeg from
sou… 105 [OK]
nginxdemos/hello NGINX webserver that serves a simple page
co… 70 [OK]
...

Let’s pull the official nginx image from the Docker Hub:

student@ubuntu:~$ docker image pull nginx

Using default tag: latest


latest: Pulling from library/nginx

Copyright the Linux Foundation 2020-2021. All rights reserved.


LFS253_12.30.2021 2

33847f680f63: Pull complete


dbb907d5159d: Pull complete
8a268f30c42a: Pull complete
b10cf527a02d: Pull complete
c90b090c213b: Pull complete
1f41b2f2bf94: Pull complete
Digest:
sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

List images cached in the local repository. The nginx image was just pulled, while the hello-world
image was pulled in a prior lab exercise when we validated the docker installation by running the test
image:

student@ubuntu:~$ docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE


nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB

List images and their digests. A digest is a hash associated with the content of each layer part of the
image. Digests ensure each layer’s integrity. The image ID is another hash, derived from the JSON
configuration file of the image. The output has been truncated for readability:

student@ubuntu:~$ docker image ls --digests

REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE


nginx latest sha256:8f335... 08b152afcfae 3 weeks ago 133MB
hello-world latest sha256:df5f5... d1165f221234 5 months ago 13.3kB

Below we see the full digest of the nginx image:

sha256:8f335768880da6baf72b70c701002b45f4932acae8d574dedfddaf967fc3ac90

Push an image to Docker Hub. Assuming the existence of an lfstudent account on Docker Hub, a user
can login from the CLI and then push an image into the registry to be shared with other users. The
following commands are provided only for illustrational purposes:

student@ubuntu:~$ docker login

Login with your Docker ID to push and pull images from Docker Hub. If you
don't
have a Docker ID, head over to https://hub.docker.com to create one.

Copyright the Linux Foundation 2020-2021. All rights reserved.


LFS253_12.30.2021 3

Username: lfstudent
Password: ********
Login Succeeded

student@ubuntu:~$ docker image push lfstudent/alpine:training

The push refers to a repository [docker.io/lfstudent/alpine]


724d404d96ef: Pushed
60ab55d3379d: Mounted from library/alpine
training: digest:
sha256:fcc29a8a772bed232fc3026f9ea5df745e57ea4c99b2306f997036510d4be0f9 size:
735

Let’s pull another image from Docker Hub, the official alpine image, and tag it:

student@ubuntu:~$ docker search alpine

NAME DESCRIPTION
STARS OFFICIAL AUTOMATED
alpine A minimal Docker image based on Alpine
Linux… 7748 [OK]
mhart/alpine-node Minimal Node.js built on Alpine Linux
483
anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.28
over A… 472 [OK]
...

student@ubuntu:~$ docker image pull alpine

Using default tag: latest


latest: Pulling from library/alpine
29291e31a76a: Pull complete
Digest:
sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379ae
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

student@ubuntu:~$ docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE


alpine latest 021b3423115f 6 days ago 5.6MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB

Copyright the Linux Foundation 2020-2021. All rights reserved.


LFS253_12.30.2021 4

student@ubuntu:~$ docker image tag alpine myalps:v1

student@ubuntu:~$ docker image ls

REPOSITORY TAG IMAGE ID CREATED SIZE


alpine latest 021b3423115f 6 days ago 5.6MB
myalps v1 021b3423115f 6 days ago 5.6MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB

If we examine closely the output, we notice that the tag command generated another image entry
myalps:v1, referencing the same image ID as the original alpine:latest image. Both the image ID
and size values are identical.

Let’s display the alpine image details. Between the image ID and its digest, we find both the alpine
and myalps tags. Try running the inspect command with the myalps:v1 image and compare the two
outputs:

student@ubuntu:~$ docker image inspect alpine

[
{
"Id":
"sha256:021b3423115ff662225e83d7e2606475217de7b55fde83ce3447a54019a77aa2",
"RepoTags": [
"alpine:latest",
"myalps:v1"
],
"RepoDigests": [
"alpine@sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379a
e"
],
"Parent": "",
"Comment": "",
"Created": "2021-08-06T17:19:45.183996158Z",
"Container":
"72bdff81d8bf6dfb5d83e6cbdd59564e419e3a97931ce4e31dd3f215eae4914c",
"ContainerConfig": {
"Hostname": "72bdff81d8bf",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,

Copyright the Linux Foundation 2020-2021. All rights reserved.


LFS253_12.30.2021 5

"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/sh\"]"
],
"Image":
"sha256:dc0d5c673ee2846463a00ec42d78344d3d5f37ac23c0723da4cd0051c16f4ef4",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "20.10.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh"
],
"Image":
"sha256:dc0d5c673ee2846463a00ec42d78344d3d5f37ac23c0723da4cd0051c16f4ef4",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",

Copyright the Linux Foundation 2020-2021. All rights reserved.


LFS253_12.30.2021 6

"Os": "linux",
"Size": 5595292,
"VirtualSize": 5595292,
"GraphDriver": {
"Data": {
"MergedDir":
"/var/lib/docker/overlay2/6bbabbf0f44c4f7955180c54680093f02d67da20463d903e5981
96b6cc35503b/merged",
"UpperDir":
"/var/lib/docker/overlay2/6bbabbf0f44c4f7955180c54680093f02d67da20463d903e5981
96b6cc35503b/diff",
"WorkDir":
"/var/lib/docker/overlay2/6bbabbf0f44c4f7955180c54680093f02d67da20463d903e5981
96b6cc35503b/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:bc276c40b172b1c5467277d36db5308a203a48262d5f278766cf083947d05466"
]
},
"Metadata": {
"LastTagTime": "2021-08-12T20:34:52.630348089Z"
}
}
]

Let’s remove a cached image from the local repository (using the --force option), then list available
images with images this time instead of image ls:

student@ubuntu:~$ docker image rm -f alpine

Untagged: alpine:latest
Untagged:
alpine@sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379ae

student@ubuntu:~$ docker images

REPOSITORY TAG IMAGE ID CREATED SIZE


myalps v1 021b3423115f 6 days ago 5.6MB
nginx latest 08b152afcfae 3 weeks ago 133MB
hello-world latest d1165f221234 5 months ago 13.3kB

Copyright the Linux Foundation 2020-2021. All rights reserved.

You might also like