How to Install and Use Docker on Arch Linux

Channel: Linux
Abstract: $ sudo systemctl status docker The output below clearly shows that Docker is up and running. To stop docker$ sudo docker ps -a The output below gives

If you are in the IT industry, chances are high that you must have heard of Docker, unless you live inside a cave or a remote region completely shut out from the rest of the world. Docker is an opensource containerization technology that has revolutionized how developers develop and deploy applications. It allows development teams to build, manage and deploy applications inside containers. A Container is a standalone prebuilt software package that packs with its own libraries and dependencies. Containers run in complete isolation of the host operating system and from each other as well.

Docker offers immense benefits. Before containerization, developers used to encounter issues when writing and deploying code on various Linux flavors. An application would work perfectly well on one system only to fail on another system. Docker standardizes code deployment and ensures that the applications can run seamlessly across various computing environments without running into dependency issues or errors. Additionally, containers contribute to vast economies of scale. Docker is resource-friendly, lightweight, and quite efficient.

In this guide, we will install Docker on Arch Linux and will also learn how to use docker to run containers.

Prerequisites
  • Arch Linux instance with SSH access
  • A sudo user configured
  • Stable internet connection
Step 1) Install Docker on Arch Linux

There are various ways that you can use to install Docker. You can install the stable package that is hosted on the Arch community repository or install it from AUR.

However, we are going to install Docker on Arch Linux from the repository using the command as shown.

$ sudo pacman -S docker

Step 2)  Managing Docker

Docker runs as a daemon service just like other services such as Apache or SSH. This means you can start, stop, restart and enable Docker service.

Once the installation is complete, start docker and enable it to start on boot up using the commands below.

$ sudo systemctl start docker
$ sudo systemctl enable docker

To confirm that docker service is running, issue the command:

$ sudo systemctl status docker

The output below clearly shows that Docker is up and running.

To stop docker, invoke the command:

$ sudo systemctl stop docker

Additionally, you can confirm the version of Docker that you are running using the docker version command shown.

$ sudo docker version

How to test and use docker

To test if everything is working as expected, we will run the following docker command to spin up a ‘hello-world‘ container

$ sudo docker run hello-world

When the command is invoked, docker contacts Docker hub and downloads a docker image called ‘hello-world’. Docker then creates a new container that runs the executable script that streams the message ‘Hello from Docker!’.

To download or pull an image from Docker hub without running it, use the syntax:

$ sudo docker pull <image-name>

For example, to pul an Nginx image, run:

$ sudo docker pull nginx

To check the images residing on your system invoke:

$ sudo docker images

From the output, you can see that we have two images so far: the Nginx and hello-world image that was downloaded earlier. The output provides additional information such as Repository, Image tag, Image ID, modification date and the size of the image.

To run an image, invoke the command:

$ sudo docker run <image-name>

However, running an image directly, may leave you with an unresponsive terminal as the image usually runs on the foreground. Therefore, it’s recommended to run it on the background using the -d option.

For example, to run the Nginx image in the background, execute:

$ sudo docker run -d nginx

To confirm current running containers, issue the command:

$ sudo docker ps

To view all containers, both running and those that have previously been stopped, execute:

$ sudo docker ps -a

The output below gives us the current Nginx container and the ‘Hello-world’ container that we run previously.

To stop a container, use the docker stop command followed by the container ID. For instance, to stop the Nginx container, execute:

$ sudo docker stop 968ff5caba7f

Some containers spawned from OS images may require some user interaction. For example, you might want to interact with a Ubuntu container image and access the shell to run commands. To achieve this, use the -it flag.

To better illustrate this, we are going to download the Ubuntu 20.04 docker image.

$ sudo docker pull ubuntu:20.04

We are now going to access the shell and run commands inside the container.

$ sudo docker run -it ubuntu:20.04

Sometimes, you may want to run a web server container and map its port to the host system to achieve this, use the -p option shown

$ sudo docker -p 8080:80 nginx

Port 80 is the port on which the Nginx container is listening to which is being mapped on port 8080 on the host. You can test this by accessing the Nginx web server using the host’s IP address as shown:

http://host-ip:8080

Conclusion

Docker is undoubtedly a powerful and robust tool especially in the DevOPs  field. It streamlines workflow and helps Developers to seamlessly build and deploy their applications without inconsistencies that come with different computing environments. We have barely scratched the surface as far Docker command usage is concerned. For more documentation, head over to the beginner’s guide. Additionally, there is the official documentation to help you out navigate Docker.

Ref From: linuxtechi
Channels: docker

Related articles