This blog will demonstrate why to use an ubuntu base image when alpine exists.
Why Use Ubuntu as a Docker Base Image When Alpine Exists?
Ubuntu and Alpine are both Linux-based images and are frequently used as base images for building Docker containers. In Docker, images are lightweight and preferable to use as base images, and these are faster in project building and deployment. However, that does not mean these are suitable in every scenario. Alpine image is much lighter and faster than the “ubuntu” image. Still, we can consider ubuntu as a base image in some scenarios due to the listed advantages:
- The ubuntu base image has an APT (Advanced Package Tool) official repository that contains thousands of packages. You can utilize the Advanced Package Tool to install additional dependencies and packages.
- It includes numerous built-in dependencies and libraries. Due to this, the user is not required to install additional dependencies separately in the top layer of the Docker container.
- Ubuntu is the most common and widely used Linux distribution. Users are more familiar with ubuntu than alpine images.
However, there are some limitations of Ubuntu as well, such as needing to be more secure and lighter in weight than the alpine image. But it does not mean ubuntu is not good as a base image.
How to Utilize Ubuntu as a Base Image?
You can use Ubuntu as a base image when you need additional dependencies in the container’s top layer. To use Ubuntu as a base image, go through the provided steps.
Step 1: Create Dockerfile
First, create a simple Dockerfile that contains the following instructions:
RUN apt-get update && apt-get install -y --no-install-recommends \
&& apt-get install -y python3 \
&& rm -rf /var/lib/apt/lists/*
CMD python3 -c "print('Docker is more simple Deployment Tool')"
According to the above snippet:
- “FROM” command specifies “ubuntu” as a base image for the container.
- “RUN” command executes the mentioned command, such as updating and installing dependencies using the APT ubuntu repository.
- “CMD” specifies the executable point for the container. In the “CMD” command, we have specified the python program that displays “Docker is more simple Deployment Tool”:
Step 2: Make New Image
Next, execute the “docker build” command to generate the image from Dockerfile:
Step 3: Create and Fire up the Container
Now, run the newly generated image to create and start the Docker container:
That’s how you can use ubuntu as the base image while alpine exists.
Conclusion
In some scenarios, the “ubuntu” base image can be preferable over the alpine, such as when users are required to install additional dependencies and extra packages in the container. Ubuntu has an APT repository that contains thousands of packages and libraries, users can easily get and install required dependencies. Another reason is that most users are more familiar with Ubuntu as it is more common than Alpine Linux. This writ e-up has explained why to use ubuntu as the base image while alpine exists.