= Services Admin

== Displaying Docker Images

To see the list of Docker images on the system, you can issue the following command.

[source,sh]
----
docker images
----

This command is used to display all the images currently installed on the system.


**Output:**

-    TAG − This is used to logically tag images.
-    Image ID − This is used to uniquely identify the image.
-    Created − The number of days since the image was created.
-    Virtual Size − The size of the image.

== Removing Docker Images

The Docker images on the system can be removed via the docker rmi command. 

[source,sh]
----
docker rmi

This command is used to remove Docker images.
Syntax

docker rmi ImageID
----


== Containers

Containers are instances of Docker images that can be run using the Docker run command. The basic purpose of Docker is to run containers. 


=== Running a Container

Running of containers is managed with the Docker run command. To run a container in an interactive mode, first launch the Docker container.

[source,sh]
----
docker run –it myimage /bin/bash 
----


=== Listing of Containers

One can list all of the containers on the machine via the docker ps command. This command is used to return the currently running containers.

[source,sh]
----
docker ps
----

=== Display the running processes of a container


With this command, you can see the top processes within a container.
Syntax

[source,sh]
----
docker top ContainerID 

Options

    ContainerID − This is the Container ID for which you want to see the top processes.
----

=== Stop a running container

This command is used to stop a running container.

[source,sh]
----
docker stop ContainerID 

Options

    ContainerID − This is the Container ID which needs to be stopped.
----

=== Attach a running container


This command is used to attach to a running container.

[source,sh]
----
docker attach ContainerID 

Options

    ContainerID − This is the Container ID to which you need to attach.
----


=== Delete container

This command is used to delete a container.

[source,sh]
----
docker rm ContainerID 

Options

    ContainerID − This is the Container ID which needs to be removed.
----

=== Container Logging

Logging is also available at the container level.

[source,sh]
----
Docker logs containerID 

Parameters

    containerID − This is the ID of the container for which you need to see the logs.
----

== Volumes

=== create

Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.

[source,sh]
----
docker run -d --name mycontainer -v /var/www/html:/var/html nginx:latest
----

=== list

[source,sh]
----
docker volume ls
----


== Network

Creates a new network. The DRIVER accepts *bridge* or *overlay* which are the built-in network drivers.

=== create bridge network

[source,sh]
----
docker network create -d bridge my-network
----

=== create overlay network

[source,sh]
----
docker network create -d overlay my-network
----

=== create  with advanced options

[source,sh]
----
docker network create \
  --driver=bridge \
  --subnet=172.28.0.0/16 \
  --ip-range=172.28.5.0/24 \
  --gateway=172.28.5.254 \
  mybr
----

=== list

[source,sh]
----
docker network ls
----

== Inspect

Low-level information on Docker objects


=== images

[source,sh]
----
docker ps IMAGE ID 
----

=== container 

[source,sh]
----
docker ps CONTAINER ID
----

=== network

[source,sh]
----
docker ps NETWORK ID
----

=== volume

[source,sh]
----
docker ps VOLUME ID
----


== repositories

You might have the need to have your own private repositories. You may not want to host the repositories on Docker Hub. For this, there is a repository container itself from Docker. Let’s see how we can download and use the container for registry.


=== Create 

[source,sh]
----
docker run –d –p 5000:5000 –-name registry registry:2

The following points need to be noted about the above command:

    Registry is the container managed by Docker which can be used to host private repositories.

    The port number exposed by the container is 5000. Hence with the –p command, we are mapping the same port number to the 5000 port number on our localhost.

    We are just tagging the registry container as “2”, to differentiate it on the Docker host.

    The –d option is used to run the container in detached mode. This is so that the container can run in the background
----


== Docker Hub 

Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub.

To run apache, you need to run the following command:

[source,sh]
----
docker run -p 8080:80 apache

Note the following points about the above  command −


    Here, apache is the name of the image we want to download from Docker hub and install on our Ubuntu machine.

    -p is used to map the port number of the internal Docker image to our main Ubuntu server so that we can access the container accordingly.
----


=== Push

use the Docker push command to push the image to our private repository.

[source,sh]
----
docker push localhost:5000/myimage
----

=== Pull

use the following Docker pull command to pull image from our private repository.

[source,sh]
----
docker pull localhost:5000/myimage
----

