Technical skill

Linux docker basics

Subject: .../LINUX

Try a web server without installing it

Imagine you want to try a web server without installing it directly on your computer. Docker can start it from an image, a package of the server’s files and supporting programs. The running copy is a container, an isolated environment for that app. On Linux it uses the host computer’s kernel, the central software that manages memory, devices, and running programs, rather than having a separate kernel of its own.

Use Docker’s docker command to start an Nginx web server and connect it to a local port:

docker run -d --rm --name demo-web -p 127.0.0.1:8080:80 nginx:alpine
docker ps
docker logs demo-web

The image is nginx:alpine. The -d option runs it in the background; --rm removes the container after it stops. -p 127.0.0.1:8080:80 connects port 8080 on the host's loopback address to port 80 in the container. A browser or curl on that computer can reach 127.0.0.1:8080. The address 127.0.0.1 means “this computer,” so binding there keeps the example local. A mapping such as 8080:80 may publish the port on all host interfaces, depending on Docker networking, so choose the host address deliberately.

docker ps shows whether the container is running; docker logs demo-web shows the app's output. Use docker inspect demo-web to read its settings. If the image includes a shell, docker exec -it demo-web sh opens one inside the running container. These commands answer different questions: current state, app output, configuration, or an interactive view.

Know who can control Docker

The docker command is a client: it sends requests to the daemon, a background service that creates containers and manages images, networks, and volumes. In a standard installation with root privileges, the daemon runs as the system’s most powerful user and listens on a local socket, a special file that lets programs communicate. A user who controls the daemon can ask it to mount host folders or access other host resources. Users in the docker group can control it, so group membership grants powerful permissions. Limit access to the socket and secure the API, the way programs send requests to the daemon, if it is reachable from another computer.

Linux uses namespaces to give a container separate views of processes, networking, and other resources. Control groups, or cgroups, account for or limit resource use. The image supplies the app’s files and supporting tools; the host supplies the kernel. Containers depend on both the host and the daemon, so keeping them secure protects the containers too.

The --rm option removes the container when it stops. Without it, use docker stop demo-web and docker rm demo-web to stop and remove it; the image remains separate. A container's writable layer lasts only as long as the container. Use a named volume for data that should survive replacement. A bind mount makes a chosen host directory available inside the container and therefore exposes those host files to the app. Run services as a normal app account with fewer permissions than root when possible. Publish only needed ports, and avoid --privileged or mounting the Docker socket into an app container, since either can give it broad access to the host. Before changing the daemon, check systemctl status docker, docker info, and the Docker context selected by the client.

Interactive exercises

Materials

Skillsets
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Skyeng DevOps TeamLead preview
image descriptionSkyeng DevOps TeamLead
by Artem Naumenko (slack2)
15 users
Skillset Skyeng Senior linux system administrator preview
image descriptionSkyeng Senior linux system administrator
by Artem Naumenko (slack2)
14 users
Skillset Skyeng SRE preview
image descriptionSkyeng SRE
by Yuliya Marochkina
12 users
Skillset Skyeng Senior PlatOps preview
image descriptionSkyeng Senior PlatOps
by Artem Naumenko (slack2)
7 users
Skillset Skyeng linux system administrator preview
image descriptionSkyeng linux system administrator
by Vitaliy Okulov
3 users
Skillset Skyeng k8s preview
image descriptionSkyeng k8s
by Roman Burnashev
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful