Docker, Ubuntu

DockerFile – Build a Ubuntu 18.04 Docker Image And Update It

There may be hundreds of custom Ubuntu 18.04 Docker images on Docker Hub that have our favorite development tools. However, many of us would rather create our Ubuntu 18.04 Docker image as base image for our various container needs. This post demonstrates how create a local Ubuntu 18.04 Docker image and update the operating system using a DockerFile.

Ubuntu, Docker And Other Tools

  • Windows 10
  • Docker for Windows – Community Edition
  • PowerShell
  • Official Ubuntu 18.04 Docker base image from Docker Hub

DockerFile And Ubuntu 18.04

We need to create a DockerFile file in some folder. On line 2, we pull a specific version of Ubuntu which is 18.04. Meanwhile, line 6 – 8 initiate an operating system update.

Using PowerShell in Command-Line Window

We will use PowerShell in the command-line to build our local Docker image. In case we need some cleaning of local images, we can clear our local cache of Docker images first. See commands on the following screenshot.

Change Directory to Specific Directory

Then, we change directory to the database-migration-tools directory where the DockerFile is. Once there, we can use the following command to verify the target directory or chek for the DockerFile.

Next, we start building the image using our DockerFile which is inside that directory. The DockerFile will pull Ubuntu 18.04 from Docker Hub and update the operating system.

Next, we kick start the building process as follows.

Once it is done, we get the following output. Our image has the a30fa1be2ddc image ID.

We can also use the following command to list our new image.

Interactively Run Ubuntu 18.04 Docker Container

Now we can test our image interactively:

To ensure we use the local image only, we create and run a container using an Image ID.

Alternatively, we could still use:

Naming Your Local Docker Image

Alternatively, we can give our local Docker image a proper name or tag. Consider the following command.

Running the command, we get the following output.

Then, we can list out the new local custom Ubuntu Docker image using the following command.

This post is part of the Docker For Developers tutorial.


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like