Introduction
In this article, I am going to begin by practicing on Docker images. I will be using my newfound knowledge of Docker images to pull, build, and launch containers.
Begin by logging in to the server using the credentials provided on AWS ec2 instance:
$ ssh cloud_user@PUBLIC_IP_ADDRESS
Pull the latest Image
Pull the latest alpine image from Docker Hub.
$ docker image pull alpine:latest latest: Pulling from library/alpine df20fa9351a1: Pull complete Digest: sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321 Status: Downloaded newer image for alpine:latest docker.io/library/alpine:latest
You can confirm it is there with:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest a24bb4013296 3 months ago 5.57MB
Pull the latest httpd image
I will pull the latest httpd image from the following command.
$ docker pull httpd:latest latest: Pulling from library/httpd bf5952930446: Pull complete 3d3fecf6569b: Pull complete b5fc3125d912: Pull complete 679d69c01e90: Pull complete 76291586768e: Pull complete Digest: sha256:3cbdff4bc16681541885ccf1524a532afa28d2a6578ab7c2d5154a7abc182379 Status: Downloaded newer image for httpd:latest docker.io/library/httpd:latest
Note: If you don’t put the version, the latest version is assumed.
Pull nginx 1.15
I am going to pull nginx version 1.15 from the below mentioned command.
$ docker pull nginx:1.15 1.15: Pulling from library/nginx 743f2d6c1f65: Pull complete 6bfc4ec4420a: Pull complete 688a776db95f: Pull complete Digest: sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68 Status: Downloaded newer image for nginx:1.15 docker.io/library/nginx:1.15
To confirm that it is there:
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE httpd latest a6ea92c35c43 4 weeks ago 166MB alpine latest a24bb4013296 3 months ago 5.57MB nginx 1.15 53f3fd8007f7 16 months ago 109MB
Compare the history
Look at the history for both the httpd and nginx images.
$ docker history httpd IMAGE CREATED CREATED BY SIZE COMMENT a6ea92c35c43 4 weeks ago /bin/sh -c #(nop) CMD ["httpd-foreground"] 0B <missing> 4 weeks ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 4 weeks ago /bin/sh -c #(nop) COPY file:c432ff61c4993ecd… 138B <missing> 4 weeks ago /bin/sh -c #(nop) STOPSIGNAL SIGWINCH 0B <missing> 4 weeks ago /bin/sh -c set -eux; savedAptMark="$(apt-m… 61MB <missing> 4 weeks ago /bin/sh -c #(nop) ENV HTTPD_PATCHES= 0B <missing> 4 weeks ago /bin/sh -c #(nop) ENV HTTPD_SHA256=740eddf6… 0B <missing> 4 weeks ago /bin/sh -c #(nop) ENV HTTPD_VERSION=2.4.46 0B <missing> 4 weeks ago /bin/sh -c set -eux; apt-get update; apt-g… 35.4MB <missing> 4 weeks ago /bin/sh -c #(nop) WORKDIR /usr/local/apache2 0B <missing> 4 weeks ago /bin/sh -c mkdir -p "$HTTPD_PREFIX" && chow… 0B <missing> 4 weeks ago /bin/sh -c #(nop) ENV PATH=/usr/local/apach… 0B <missing> 4 weeks ago /bin/sh -c #(nop) ENV HTTPD_PREFIX=/usr/loc… 0B <missing> 4 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B <missing> 4 weeks ago /bin/sh -c #(nop) ADD file:3af3091e7d2bb40bc… 69.2MB
Note the following command gives an error because the latest version is assumed:
$ docker history nginx Error response from daemon: No such image: nginx:latest
When you specify the right version, the command succeeds:
$ docker history nginx:1.15 IMAGE CREATED CREATED BY SIZE COMMENT 53f3fd8007f7 16 months ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon… 0B <missing> 16 months ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B <missing> 16 months ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 16 months ago /bin/sh -c ln -sf /dev/stdout /var/log/nginx… 22B <missing> 16 months ago /bin/sh -c set -x && apt-get update && apt… 54.1MB <missing> 16 months ago /bin/sh -c #(nop) ENV NJS_VERSION=1.15.12.0… 0B <missing> 16 months ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.15.12… 0B <missing> 16 months ago /bin/sh -c #(nop) LABEL maintainer=NGINX Do… 0B <missing> 16 months ago /bin/sh -c #(nop) CMD ["bash"] 0B <missing> 16 months ago /bin/sh -c #(nop) ADD file:fcb9328ea4c115670… 55.3MB
Conclusion
Basically, that’s all you need to know about working with Docker images. There are more tutorials that will go into deeper explanation of using Docker thoroughly, but this is a simple article to just get familiar with images.