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
- 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.
# Pull base image.
LABEL maintainer="Karl San Gabriel <email@example.com>"
# Install updates to base image
&& apt-get install -y
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.
docker build .
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.
docker image ls
Interactively Run Ubuntu 18.04 Docker Container
Now we can test our image interactively:
docker run -i -t ea4c82dcd15a /bin/bash
To ensure we use the local image only, we create and run a container using an Image ID.
Alternatively, we could still use:
docker run -i -t ubuntu:12.04 /bin/bash
Naming Your Local Docker Image
Alternatively, we can give our local Docker image a proper name or tag. Consider the following command.
docker build . -t turreta_ubuntu18.04:1.00
Running the command, we get the following output.
Then, we can list out the new local custom Ubuntu Docker image using the following command.
docker image ls
This post is part of the Docker For Developers tutorial.