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.
1 2 3 4 5 6 7 8 9 | # Pull base image. FROM ubuntu:18.04 LABEL maintainer="Karl San Gabriel <karl.sangabriel@xxxxxxxxxx.xxx>" # Install updates to base image RUN \ apt-get update -y \ && 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.
1 | pwd |
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.
1 | 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.
1 | docker image ls |
Interactively Run Ubuntu 18.04 Docker Container
Now we can test our image interactively:
1 | 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:
1 | 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.
1 | 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.
1 | docker image ls |
This post is part of the Docker For Developers tutorial.