Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Docker: A Practical Guide with Arch Linux Setup: Part-1
Sujit Kumar
Sujit Kumar

Posted on • Edited on

     

Docker: A Practical Guide with Arch Linux Setup: Part-1

Docker Intro:

Docker has revolutionized the way we develop, deploy, and run applications. It provides a lightweight and efficient solution for packaging, distributing, and running software in isolated environments called containers. This blog post aims to guide you through the basics of Docker, including its setup on an Arch-based Linux system.

Docker Basics

Installation

To install Docker on Arch Linux, you can use the following commands:

sudopacman-S dockersudosystemctl start dockersudosystemctlenabledocker
Enter fullscreen modeExit fullscreen mode

This will install Docker and start the Docker daemon.

Adding User to Docker group

To add the user to the docker group, use the following command:

sudo usermod -aG docker $USER
Enter fullscreen modeExit fullscreen mode

This will add the user to the docker group without requiring sudo privileges.
Note: It requires to restart your device.

Running a Container

Let's start with a simple example. To run an Ubuntu container interactively, use:

docker run-it ubuntu
Enter fullscreen modeExit fullscreen mode

Find Images in Docker Hub

docker search jenkins
Enter fullscreen modeExit fullscreen mode

Download Docker Image from Docker Hub to Local

docker pull jenkins
Enter fullscreen modeExit fullscreen mode

Delete Local image

docker rmi image_name
Enter fullscreen modeExit fullscreen mode

This command pulls the Ubuntu image from the Docker Hub and starts an interactive shell within the container.

Managing Containers

  • Start/Stop a Container:
docker start container_namedocker stop container_name
Enter fullscreen modeExit fullscreen mode
  • List Containers:
docker ps-a
Enter fullscreen modeExit fullscreen mode
  • Go Inside Docker Container:
docker attach container_name
Enter fullscreen modeExit fullscreen mode
  • Execute a Command in a Running Container:
dockerexeccontainer_namecommand
Enter fullscreen modeExit fullscreen mode
  • Attach to a Running Container:
dockerexec-it container_name bash
Enter fullscreen modeExit fullscreen mode
  • Remove a Container:
dockerrmcontainer_name
Enter fullscreen modeExit fullscreen mode
  • Inspect Container Details:
docker inspect container_name
Enter fullscreen modeExit fullscreen mode
  • Diff Containers
docker diff container_name
Enter fullscreen modeExit fullscreen mode
  • Commit changes into container and create updated image
docker commit container_name new_image_name
Enter fullscreen modeExit fullscreen mode

Listing Images

docker images
Enter fullscreen modeExit fullscreen mode

Dockerization with Dockerfile

A Dockerfile is a script that contains a set of instructions for building a Docker image. Here's a basic example for a Node.js application:

FROM ubuntuRUNapt-get update&&\    apt-getinstall-y curl&&\    curl-sL https://deb.nodesource.com/setup_14.x | bash&&\    apt-getinstall-y nodejsWORKDIR /appCOPY package.json package-lock.json ./RUNnpminstallCOPY . .CMD ["node", "main.js"]
Enter fullscreen modeExit fullscreen mode

To build the image, navigate to the directory containing the Dockerfile and run:

docker build-t your_image_name.
Enter fullscreen modeExit fullscreen mode

Container Networking

To expose a port from the container to the host system, use the-p flag. For example:

docker run-it-p 1025:1025 your_image_name
Enter fullscreen modeExit fullscreen mode

This maps port 1025 on the host to port 1025 on the container.

Conclusion

Docker simplifies the process of packaging, distributing, and running applications. In this guide, we covered basic Docker commands, the creation of Dockerfiles, and container networking. This should serve as a solid foundation for further exploration into the world of containerization.
Happy Dockering!

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am Full Stack Web Developer..
  • Location
    India
  • Joined

More fromSujit Kumar

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp