Learn the commands to create an Alpine Docker container on Ubuntu using the command line to run a lightweight Linux for various applications.
Alpine Linux is popular because of its small size and fast speed. On Docker, its image is of few Mbs, hence consuming less space and resources. Users can opt for it to install a web server, database server such as MySQL, and more… It uses its own package manager called apk to install the packages available through its repository. Being lightweight is the reason why many platforms used it to set up container services.
Here in this article, we will see the steps to install Alpine Image on Docker to create a container. However, those who are interested in running the docker service on Alpine Linux can see our article: How to install Docker Engine on Alpine Linux.
Steps to install Alpine on the Docker container
To follow this tutorial, we are assuming you already have Docker service installed on your existing system and now you want to use the same to create a container with Alpine Image.
1. Pull Docker Alpine Image
By default, the minimal Docker image based on Alpine Linux is available in the Docker Hub repository. Hence, we just need to pull and install it to create a container. Here is the command to follow:
sudo docker pull alpine
2. Check the available images
Let’s check whether the downloaded image is available to create a container or not. For that just run the given command:
sudo docker images
3. Create Alpine Linux Container
In the result, you will see the Alpine image you have just pulled from the Docker library. Now, we can create as many containers running with Alpine Linux. Here is the command to create one.
docker run -it --name myalpine -d alpine
In the above command:
--name myalpineis the name of the container we want to create.
alpine is the name of the image we have downloaded
-d is the option to run the container in the background.
To check what are the containers already running on your system, we can use:
sudo docker ps
4. Connect to Alpine container command line
Now, we have the Alpine Linux container running in the background, let’s connect to its command for issuing commands.
sudo docker exec -it --user root myalpine /bin/sh
Although we have mentioned the particular user in the above command, however, even if you haven’t, by default it will connect using the root user only.
To check the version:
To exit the command line of Alpine, type:
5. Set root password
If you want to set a root password for the Alpine Linux container then after switching to its command line using the previous step, just type:
Enter the new password two times and you are done.
⇒ How to install XFCE GUI on Alpine Linux
⇒ How to install the FireFox browser in Alpine Linux
⇒ Install MongoDB Server on Alpine Linux
⇒ How to install and use Rocky Linux Docker container