11/22/2021»»Monday

Run Ubuntu Container

Apr 01, 2019

Hi, I’m new to docker. So I did run docker run -it ubuntu I did some installations (apache, php, etc) on my container. Now when I start my container it stops right away. No idea how to enter to command line and keep my web server running within that container. While I’m reading a book I would appreciate if you can give me some hints and directions. The chapter will also provide an overview of some of the Ubuntu container management tools. Once the basics of containers have been covered in this chapter, the next chapter will work through some practical examples of creating and running containers on Ubuntu. 1.1 Linux Containers and Kernel Sharing. Here we are using Ubuntu image. Once the image downloaded and extracted by the system, click on the Run icon and you will see a pop-up to customize container settings before actually starting it. You can change the Container Name, increase or decrease Memory and CPU capacity, mount container volume, link to another container,.

  • For the rest, here is how you can run Ubuntu container in Chrome OS. Boot up your Chromebook. Do not open any Linux app. Open the Chrome browser and press Ctrl + Alt + T to launch the Crosh shell. Start the terminal with this command: vmc start termina.
  • If you just want to run Ubuntu as your default container on Crostini, with full Chrome OS integration including files and launcher icons, this section is for you. This 'cheat sheet' contains the relevant info from the above post for installing Ubuntu 18.04 as the default container (penguin) directly on a Chrome OS device which already has.

3min Read

Just like Linux was an accidental revolution by Linus Torvalds, Docker was by Solomon Hykes. Solomon was trying to figure out a solution for programmers to provide a code that runs the same both on their development as well as the production environment and this resulted in the creation of Docker Containers. In this tutorial, we’ll show you how you can start a Docker container on your VPS, along with some extra tips and commands.

Today Docker is the most popular software container platform.

Docker Explained

At a very basic level it solves the issue of an application running on one platform but not on others. Although present in the entire software development lifecycle, Docker Containers main use is in deployment.

What are Docker Containers

Docker Containers are running instances of Docker images. Running an Image creates a Docker container. Images provide a template that can be used for the creation of containers. They contain information about what’s required to create containers. Images can either be stored locally or remotely. If you need help installing Docker, check out our tutorials for CentOS 7 or Ubuntu 18.04.

How to Start a Docker Container

Container

Remember, before starting, you need to access your VPS server with SSH. Check out our PuTTY tutorial if you’re having trouble.

To list all Dockers images on your system you can use the command:

If you want to display additional information enter the following command in the command line:

We don’t have any Docker Images on our system, so let’s pull an image first. To do that, first go to Docker hub. Here you can find hundreds of Docker Images. We’ll pull an Ubuntu image. You can browse each image’s page to see more details about the Image:

We can pull the image with the command:

You can replace <image name> with hundreds of images found on Docker Hub like CentOS, MySQL, mariaDB, Python, etc.

Using the -q option will list only numeric IDs of Images available on your system.

-f is the filter flag. If we wanted to list all images that are not dangling – tagged or referenced by a container – we would use the command:

Now that we know how to pull and locate an image to start a Docker container, we can get to work.

Next we see how to run an Image, by running an Image we actually create a container out of that image. Lets run our ubuntu image. To start a Docker container use the command:

We’ll run the Ubuntu image. So the command will be:

The container is created, but not started

To start the container we use a command like this:

Here –name MyContainer is simply how we want to name the running process, while -it ubuntu bash, names which container we’re running.

Nowe we can open another terminal window, SSH into the server and run the command:

Open another terminal and issue following command.

We can now see that the container named MyContainer is now running.

To stop the container issue following command:

If we wish to see the top process of a container we can run the command:

It would look like this:

To see stats of a container like its CPU utilization, memory usage, etc.:

Lastly, if we wish to kill a Docker container:

That’s all there is to it! You’re ready to start a Docker container and put it to use!

Wrap Up

Docker is an incredibly useful tool for any developer. The ability to seamlessly test, deploy and develop applications is a utility that can speed up workflow exponentially. In this tutorial, we show how to start a Docker container, along with some other commands that will definitely come in handy.

To learn more we suggest checking out our other tutorials, or Docker’s official documentation!

Edward is an expert communicator with years of experience in IT as a writer, marketer, and Linux enthusiast. IT is a core pillar of his life, personal and professional. Edward's goal is to encourage millions to achieve an impactful online presence. He also really loves dogs, guitars, and everything related to space.

The preceding chapters covered the concept of virtualization with a particular emphasis on creating and managing virtual machines using KVM. This chapter will introduce a related technology in the form of Linux Containers. While there are some similarities between virtual machines and containers, there are also some key differences that will be outlined in this chapter along with an introduction to the concepts and advantages of Linux Containers. The chapter will also provide an overview of some of the Ubuntu container management tools. Once the basics of containers have been covered in this chapter, the next chapter will work through some practical examples of creating and running containers on Ubuntu.

1.1 Linux Containers and Kernel Sharing

In simple terms, Linux containers can be thought of as a lightweight alternative to virtualization. In a virtualized environment, a virtual machine is created that contains and runs the entire guest operating system. The virtual machine, in turn, runs on top of an environment such as a hypervisor that manages access to the physical resources of the host system.

Containers work by using a concept referred to as kernel sharing which takes advantage of the architectural design of Linux and UNIX-based operating systems.

In order to understand how kernel sharing and containers work it helps to first understand the two main components of Linux or UNIX operating systems. At the core of the operating system is the kernel. The kernel, in simple terms, handles all the interactions between the operating system and the physical hardware. The second key component is the root file system which contains all the libraries, files and utilities necessary for the operating system to function. Taking advantage of this structure, containers each have their own root file system but share the kernel of the host operating system. This structure is illustrated in the architectural diagram in Figure 30-1 below.

This type of resource sharing is made possible by the ability of the kernel to dynamically change the current root file system (a concept known as change root or chroot) to a different root file system without having to reboot the entire system. Linux containers are essentially an extension of this capability combined with a container runtime, the responsibility of which is to provide an interface for executing and managing the containers on the host system. A number of container runtimes are available including Docker, lxd, containerd and CRI-O.

Figure 30-1

1.2 Container Uses and Advantages

The main advantage of containers is that they require considerably less resource overhead than virtualization allowing many container instances to be run simultaneously on a single server, and can be started and stopped rapidly and efficiently in response to demand levels. Containers run natively on the host system providing a level of performance that cannot be matched by a virtual machine.

Containers are also extremely portable and can be migrated between systems quickly and easily. When combined with a container management system such as Docker, OpenShift and Kubernetes, it is possible to deploy and manage containers on a vast scale spanning multiple servers and cloud platforms, potentially running thousands of containers.

Containers are frequently used to create lightweight execution environments for applications. In this scenario, each container provides an isolated environment containing the application together with all of the runtime and supporting files required by that application to run. The container can then be deployed to any other compatible host system that supports container execution and run without any concerns that the target system may not have the necessary runtime configuration for the application – all of the application’s dependencies are already in the container.

Containers are also useful when bridging the gap between development and production environments. By performing development and QA work in containers, those containers can then be passed to production and launched safe in the knowledge that the applications are running in the same container environments in which they were developed and tested.

Containers also promote a modular approach to deploying large and complex solutions. Instead of developing applications as single monolithic entities, containers can be used to design applications as groups of interacting modules, each running in a separate container.

One possible drawback of containers is the fact that the guest operating systems must be compatible with the version of the kernel which is being shared. It is not, for example, possible to run Microsoft Windows in a container on a Linux system. Nor is it possible for a Linux guest system designed for the 2.6 version of the kernel to share a 2.4 version kernel. These requirements are not, however, what containers were designed for. Rather than being seen as limitations, therefore, these restrictions should be viewed as some of the key advantages of containers in terms of providing a simple, scalable and reliable deployment platform.

1.3 Ubuntu Container Tools

Run Ubuntu Container On Windows 10

There a number of options available for creating and managing containers on Ubuntu. One option is to download and install the standard tools provided by Docker. In this book, however, we are going to focus on a new set of tools that have been developed by Red Hat, Inc. and are widely used on other Linux distributions such as CentOS, Fedora and Red Hat Enterprise Linux. There are a number of reasons for this choice. First, these tools are fully compatible with the tools supplied by Docker (including using the same command-line options). More importantly, these tools have the advantage that they can be used without the need to have the Docker daemon running in the background. This container tool set consists of the following utilities:

  • buildah – A command-line tool for building container images.
  • podman – A command-line based container runtime and management tool. Performs tasks such as downloading container images from remote registries and inspecting, starting and stopping images.
  • skopeo – A command-line utility used to convert container images, copy images between registries and inspect images stored in registries without the need to download them.
  • runc – A lightweight container runtime for launching and running containers from the command-line.

All of the above tools are compliant with the Open Container Initiative (OCI), a set of specifications designed to ensure that containers conform to the same standards between competing tools and platforms.

1.4 The Docker Registry

Although Ubuntu is provided with a set of tools designed to be used in place of those provided by Docker, those tools still need access to Ubuntu images for use when building containers. For this purpose, the Ubuntu team maintains a set of Ubuntu container images within the Docker Hub. The Docker Hub is an online container registry made of multiple repositories, each containing a wide range of container images available for download when building containers. The images within a repository are each assigned a repository tag (for example, 20.04, latest etc) which can be referenced when performing an image download. The following, for example, is the URL of the Ubuntu 20.04 image contained within the Docker Hub:

In addition to downloading (referred to as “pulling” in container terminology) container images from Docker and other third party hosts registries, you can also use registries to store your own images. This can be achieved either by hosting your own registry, or by making use of existing services such as those provided by Docker, Amazon AWS, Google Cloud, Microsoft Azure and IBM Cloud to name a few of the many options.

1.5 Container Networking

By default, containers are connected to a network using a Container Networking Interface (CNI) bridged network stack. In the bridged configuration, all the containers running on a server belong to the same subnet and, as such, are able to communicate with each other. The containers are also connected to the external network by bridging the host system’s network connection. Similarly, the host is able to access the containers via a virtual network interface (usually named cni0) which will have been created as part of the container tool installation.

Docker Run Ubuntu Container

1.6 Summary

Run Ubuntu Container Kubernetes

Linux Containers offer a lightweight alternative to virtualization and take advantage of the structure of the Linux and Unix operating systems. Linux Containers essentially share the kernel of the host operating system, with each container having its own root file system containing the files, libraries and applications. Containers are highly efficient and scalable and provide an ideal platform for building and deploying modular enterprise level solutions. A number of tools and platforms are available for building, deploying and managing containers including third-party solutions and those provided with Ubuntu.

Most Viewed Posts