12/28/2021

Ubuntu 16 Docker

40

Hello everyone, today I am going to show you how to install Docker Community Edition on Ubuntu 16.04 server. This is the Docker official way to get the latest version of Docker. Its pretty simple to install this Docker CE. We have been tested this tutorial on Ubuntu 16.04.2 server edition.

Docker installed with the instructions from Step 1 and Step 2 of How To Install and Use Docker on Ubuntu 16.04 Once these are in place, you’re ready to follow along. Note: Even though the Prerequisites give instructions for installing Docker on Ubuntu 16.04, the docker commands in this article should work on other operating systems as long as. Run a quick ‘docker info’ command to ensure that you get information back from Docker and that everything looks OK. Containers, Docker, VMware 16.04, Docker, host, install, ubuntu, VMware, Workstation.

Steps to install Docker Community Edition on Ubuntu 16.04

Install

Docker Pull Ubuntu 16

Step 1. Setup the repository

First, we need to install some packages and setup the official Docker repository on Ubuntu 16.04. Connect to Ubuntu 16.04 via SSH and copy paste the following command. I recommend to use copy and paste to avoid misspelling on the commands.

Install required packages

Add the GPG key

Add the repository

Update Ubuntu

Step 2. Install Docker

Output:

Step 3. Verify the installation

Now we need to check if Docker CE is correctly installed.

Check Docker Daemon status

Now try to run Hello World using Docker command as follow:

“Live boldly. Push yourself. Don’t settle.” ― Jojo Moyes, Me Before You

Contents

  • 7. Running the Docker Image
  • Conclusion

1. Introduction

Docker is a very cool technology for running whole operating systems inside a process. You run a command on the host system and a whole new virtual system springs into existence, ready to operate as you have configured it. This capability offers unprecedented power and flexibility to build and throw away infrastructure as you wish. You could use this capability in test environments, running applications with differing system requirements in the same host, and a lot more.

We have previously covered installing the Nginx web server and enabling it with SSL support. We have also talked about hardening the Nginx SSL installation. These activities were performed on a new operating system build. Let us now demonstrate how to run the Nginx web server with SSL inside of a docker container. We also show you how to use this running container to take over the duties of web serving on the host. The advantage of hosting a web server inside a docker container are many; for example, you could separate the web serving part from the database, with the database also running inside a docker container. (We will demonstrate this configuration in a future article.)

Ubuntu

2. Preparation

Let us now see what preparatory steps are required to run Nginx inside a docker container. Obviously, the first thing we want to do on a new system is to install docker. Assuming Ubuntu 16.04 host server, run the following command as the root user to install docker.

Assuming you are smart enough not to do all development as the root user, set up a non-privileged user account. In our case this account is called aurora. Pick whatever name suits you.

Now the user aurora can log in (after setting password, or enabling password-less ssh access) and run docker commands.

3. A Docker Primer

The Docker application is a server that runs on a system and is controlled by a command called docker. The docker can run instances of an image which is a complete operating system packed into a file. This running instance is known as a container, as in a container for an operating system. You can start and stop these containers are per demand. You can also completely delete containers and images from the docker system.

To get started, you can build an image from a base operating system image, and configure it to your specifications. To ease the repeated building and configuration of images, Docker uses a build file known as the Dockerfile. Here is the complete reference to the Dockerfile, and the directives it can include.

4. Preparing the Dockerfile

We will now use a Dockerfile to prepare the image to can run the Nginx web server.

First, we choose Ubuntu 16.04 as the base server image using the Dockerfile clause FROM. The MAINTAINER should list your name and email address.

Next, we run a few commands to configure the base image.

First is to update the server OS.

We obviously need to install nginx. Also require net-tools which contains the netstat command.

Add a non-privileged user for normal operation.

Next, we adjust the configuration of Nginx by removing some unneeded files.

Docker supports its own networking inside the container. By default, listen ports opened inside the running container are not accessible from outside the container. This is a security feature. Opened ports must be explicitly declared to be accessible from outside. Since Nginx opens ports 80 and 443, and we want these accessible from the outside, we need to explicitly tell Docker to expose them.

We have configured Nginx for SSL (HTTPS) and these are the files that are being used. We copy these files from the build environment to the correct path inside the image. We discuss contents of these files below. You can also refer to this article for the complete details.

The last directive in our Dockerfile is to have Nginx run in the foreground inside the container.

5. Configuring Nginx

Note, we have a detailed article describing how to configure Nginx for SSL. Below we present only the changes required to the stock Nginx installation to enable SSL.

  • nginx/ssl: This is a directory containing the SSL certificate (bundled) and the private key used to sign the CSR.
  • nginx/snippets: This is a directory which includes a single file called ssl.conf. We have discussed here how the various clauses which enhance the SSL setup of your Nginx web server.It looks like this:
  • nginx/sites-available: This contains a single file called default which provides the configuration for the default site. For our case, we have added these lines for configuring SSL.

6. Building the Docker Image

Docker.io

Now that we have a Dockefile, we can build our image from it using the following command. It tells docker to build the image called mynginx with the tag latest and replace any old images with the freshly built one. The last argument tells docker to pick up relative file names from the current directory. Specifically, the directory contains an nginx directory with the above listed files.

After you run this command, docker goes through the process of downloading the base Ubuntu 16.04 image and configuring it. After it is done, it shows something like:

Ubuntu 16 Remove Docker

Ubuntu

Ubuntu 16 Install Docker

You can check that the image has been added to Docker using the command:

To discard the image (for re-building):

For a complete cleanup of all intermediate images, use the following command:

7. Running the Docker Image

Ubuntu 18 Docker

Now that we have built our Docker Nginx image, we try to run it.

This command run the mynginx image with the latest tag, and maps the exposed ports as follows: port 80 from the container is mapped to port 80 on the host, and likewise for port 443.

When this command completes successfully, you will see that the host is listening on ports 80 and 443. The requests are routed automatically to Nginx running inside the docker container.

At this point, you can visit your site using a browser and it should just work. Check both HTTP and HTTPS.

Ubuntu 16 Docker Software

7.1. Stopping the Container

To stop a container, you need the container id. Look it up by listing the containers.

You can stop the docker container using:

7.3. Removing the Container

Remove the container from docker using the following command. Again you can lookup the container id if needed.

8. The Dockerfile

Ubuntu 16.10 Download

For reference, here is the complete Dockerfile.

Ubuntu 16 Docker.io

Conclusion

In this article, we learned how to install the Nginx web server in a Docker container and run it to turn the host into a web server. We have also made changes to Nginx configuration to SSL-enable it.

  • Most Viewed News

    • Download Suitcase Fusion 9
    • Unity Editor Download Mac
    • Install Jupyter Notebook On Mac
    • Tropico 6 Mac Download Free
    • Ubuntu Docker Update