Running a Docker Container on Ubuntu 16.04

The hello-world container you ran in the previous step is an example of a container that runs and exits after emitting a test message. Containers can be much more useful than that, and they can be interactive. After all, they are similar to virtual machines, only more resource-friendly.

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

docker run -it ubuntu

Note: The default behavior for the run command is to start a new container. Once you run the preceding the command, you will open up the shell interface of a second ubuntu container.

Your command prompt should change to reflect the fact that you’re now working inside the container and should take this form:


Note: Remember the container id in the command prompt. In the preceding example, it is 9b0db8a30ad1. You’ll need that container ID later to identify the container when you want to remove it.

Now you can run any command inside the container. For example, let’s update the package database inside the container. You don’t need to prefix any command with sudo, because you’re operating inside the container as the root user:

apt-get update

Then install any application in it. Let’s install Node.js:

apt-get install -y nodejs

This installs Node.js in the container from the official Ubuntu repository. When the installation finishes, verify that Node.js is installed:

node -v

You’ll see the version number displayed in your terminal:


Any changes you make inside the container only apply to that container.

To exit the container, type exit at the prompt.

Let’s look at managing the containers on our system next.

You can read more details form digital ocean and docker’s official doc.