Introduction The docker command now consists of multiple management commands having related sub-commands embedded within them. Some of the examples of management commands are builder, config, container, image, network, etc. You could view the full list of management commands available with docker by typing docker –help. In this article, we’ll discuss the sub-commands associated with two of the management commands namely image and container as we are likely to use them the most while working with docker. We’ll start with docker images. To view a list of available commands with the docker image command type docker image –help. List images: To list images we use docker image ls. [sahil@linuxnix ~]$ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE [sahil@linuxnix ~]$ Download an image: From the docker image ls command output, we determined that we don’t have any image on the system. So, let’s download an image using the docker image pull command. [sahil@linuxnix ~]$ docker image pull nginx Using default tag: latest latest: Pulling from library/nginx f5d23c7fed46: Pull complete 918b255d86e5: Pull complete 8c0120a6f561: Pull complete Digest: sha256:eb3320e2f9ca409b7c0aa71aea3cf7ce7d018f03a372564dbdb023646958770b Status: Downloaded newer image for nginx:latest docker.io/library/nginx:latest Here we pulled an image comprising the nginx web server installed from the Docker Hub. We’ll talk in detail about what happens during an image pull in a separate post docker images. Fetch image details: To view details about an image type docker image...Read More
Author: Sahil Suri
Introduction When we create a container the general philosophy is that the container comes up, does the task it’s intended to perform and then goes away. Containers are basically meant to be ephemeral in nature but we can make a container last a little while longer. In this post we’ll talk about running containers, logging into containers and the container life cycle in general. First, let’s answer the question why would you want a container to last? If you’ve dockerized an existing application or wrote some code to run within the container you might want the container to hang around a bit to validate that your code is working as per expectation. Working with containers: Let’s first check which images do we have available on the system. [sahil@linuxnix ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> e1c1d07a11b5 5 hours ago 182MB ubuntu 16.04 13c9f1285025 2 weeks ago 119MB hello-world latest fce289e99eb9 6 months ago 1.84kB [sahil@linuxnix ~]$ From the above output, you can see that we have three images available with us. The hello-world image we ran to validate our install, the ubuntu 16.04 image that we pulled from docker hub and finally the untagged container that we created using our dockerfile and based it off the ubuntu container. We’ll now run a container from the image that we created and name it as well all...Read More
Introduction When we talked about the Docker hub we mentioned a scenario wherein we would use an Ubuntu 16.04 image as our base image, update it and install Python 3 on it. In our last post on Docker images we successfully downloaded the Ubuntu 16.04 image that we will be using. In this post, we will explain how to create a new image using a Dockerfile by making changes to the base image. We will not be going in-depth about all the configuration changes we can make to an image using a Dockerfile and will instead focus on applying some basic modifications. Creating a dockerfile: To keep things clean, I’ll be creating a new directory and will create our dockerfile in that directory. [sahil@linuxnix ~]$ mkdir linuxnix-docker [sahil@linuxnix ~]$ cd linuxnix-docker/ Here is our dockerfile [sahil@linuxnix linuxnix-docker]$ cat dockerfile FROM ubuntu:16.04 RUN apt-get update RUN apt-get install -y python3 [sahil@linuxnix linuxnix-docker]$ Looks simple, doesn’t it? The FROM attribute denotes the base image to use for the creation of a new image using this dockerfile. We will be using out ubuntu 16.04 image. In some dockerfiles you might see FROM scratch written. This implies that the image was not created using a base image. Next, we have two RUN statements, one for the image update and another one for the python3 install. Each RUN statement will add a new layer to...Read More
Take this course
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.