Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Containers in OpenStack

You're reading from   Containers in OpenStack Leverage OpenStack services to make the most of Docker, Kubernetes and Mesos

Arrow left icon
Product type Paperback
Published in Dec 2017
Publisher Packt
ISBN-13 9781788394383
Length 176 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Pradeep Kumar Singh Pradeep Kumar Singh
Author Profile Icon Pradeep Kumar Singh
Pradeep Kumar Singh
Madhuri Kumari Madhuri Kumari
Author Profile Icon Madhuri Kumari
Madhuri Kumari
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Working with Containers FREE CHAPTER 2. Working with Container Orchestration Engines 3. OpenStack Architecture 4. Containerization in OpenStack 5. Magnum – COE Management in OpenStack 6. Zun – Container Management in OpenStack 7. Kuryr – Container Plugin for OpenStack Networking 8. Murano – Containerized Application Deployment on OpenStack 9. Kolla – Containerized Deployment of OpenStack 10. Best Practices for Containers and OpenStack

Docker hands-on

This section explains how to use Docker to run any application inside containers. The Docker installation explained in the previous section also installs the docker command-line utility or the Docker client. Let's explore the docker command. Using the docker command consists of passing it a chain of options and commands followed by arguments.

The syntax takes this form:

$ docker [option] [command] [arguments]
# To see help for individual command
$ docker help [command]  

To view system wide information about Docker and the Docker version, use the following:

$ sudo docker info
$ sudo docker version  

Docker has many subcommands to manage multiple resources managed by the Docker daemon. Here is a list of management commands supported by Docker:

Management command

Description

Config

Manages Docker configs

container

Manages containers

image

Manages images

network

Manages networks

Node

Manages Swarrn nodes

Plugin

Manages plugins

secret

Manages Docker secrets

Service

Manages services

Stack

Manages Docker stacks

Swarm

Manages swarm

System

Manages Docker

Volume

Manages volumes

 

In the next section, we will explore container and image resources.

Working with Docker images

An image is a lightweight, standalone executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and configuration files. Docker images are used to create Docker containers. Images are stored in the Docker Hub.

Listing images

You can list all of the images that are available in the Docker host by running the Docker images subcommand. The default Docker images will show all top-level images, their repository and tags, and their size:

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
wordpress           latest              c4260b289fc7        10 days ago         406MB
mysql               latest              c73c7527c03a        2 weeks ago         412MB
hello-world         latest              1815c82652c0        2 months ago        1.84kB

Getting new images

Docker will automatically download any image that is not present in the Docker host system. The docker pull subcommand will always download the image that has the latest tag in that repository if a tag is not provided. If a tag is provided, it pulls the specific image with that tag.

To pull a base image, do the following:

$ sudo docker pull Ubuntu 
# To pull specific version 
$ sudo docker pull ubuntu:16.04 

Searching Docker images

One of the most important features of Docker is that a lot of people have created Docker images for a variety of purposes. Many of these have been uploaded to Docker Hub. You can easily search for Docker images in the Docker Hub registry by using the docker search subcommand:

$ sudo docker search ubuntu
NAME                                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
rastasheep/ubuntu-sshd                         Dockerized SSH service, built on top of of...   97                   [OK]
ubuntu-upstart                                 Upstart is an event-based replacement for ...   76        [OK]
ubuntu-debootstrap                             debootstrap --variant=minbase --components...   30        [OK]
nuagebec/ubuntu                                Simple always updated Ubuntu docker images...   22                   [OK]
tutum/ubuntu                                   Simple Ubuntu docker images with SSH access     18  

Deleting images

To delete an image, run the following:

$ sudo docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:b2ba691d8aac9e5ac3644c0788e3d3823f9e97f757f01d2ddc6eb5458df9d801
Deleted: sha256:05a3bd381fc2470695a35f230afefd7bf978b566253199c4ae5cc96fafa29b37
Deleted: sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959b624eab41bbf126272a023  

Please refer to the Docker documentation for the rest of the commands related to Docker images.

Working with Docker containers

A container is a runtime instance of an image. It runs completely isolated from the host environment by default, only accessing host files and ports if configured to do so.

Creating containers

Launching a container is simple, as docker run passes the image name you would like to run and the command to run this within the container. If the image doesn't exist on your local machine, Docker will attempt to fetch it from the public image registry:

$ sudo docker run --name hello_world ubuntu /bin/echo hello world  

In the preceding example, the container will start, print hello world, and then stop. Containers are designed to stop once the command executed within them has exited.

As an example, let's run a container using the latest image in Ubuntu. The combination of the -i and -t switches gives you interactive shell access to the container:

$ sudo docker run -it ubuntu
root@a5b3bce6ed1b:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  
run sbin srv sys tmp usr var

Listing containers

You can list the all containers running on the Docker host using the following:

# To list active containers
$ sudo docker ps
    
# To list all containers
$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
2db72a5a0b99        ubuntu              "/bin/echo hello w..."  
58 seconds ago Exited (0) 58 seconds ago
hello_world

Checking container's logs

You can also view the information logged by a running container using the following:

$ sudo docker logs hello_world
hello world  

Starting containers

You can start a stopped container using the following:

$ sudo docker start hello_world  

Similarly, you can use commands such as stop, pause, unpause, reboot, restart, and so on to operate containers.

Deleting containers

You can also delete a stopped container using the following:

$ sudo docker delete hello_world
    
# To delete a running container, use -force parameter
$ sudo docker delete --force [container]  

Please refer to the Docker documentation for the rest of the commands related to Docker containers.

You have been reading a chapter from
Containers in OpenStack
Published in: Dec 2017
Publisher: Packt
ISBN-13: 9781788394383
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image