Operation and Maintenance
Linux Operation and Maintenance
How to run your first Docker container on Linux? (Hello World Example)
How to run your first Docker container on Linux? (Hello World Example)
成功运行首个Docker容器只需三步:安装Docker并启动服务、添加用户到docker组、执行docker run hello-world输出“Hello from Docker!”。

Run your first Docker container on Linux with the classic Hello World example in just a few steps — no prior Docker experience needed.
Install Docker on your Linux system
Docker isn’t pre-installed on most Linux distributions. You’ll need to add the official repository and install it.
- For Ubuntu/Debian: update packages, add Docker’s GPG key and repo, then run
sudo apt install docker.io - For CentOS/RHEL/Fedora: use
dnf install dnf-plugins-core, enable the Docker repo, then runsudo dnf install docker-ce - Start and enable the service:
sudo systemctl start docker && sudo systemctl enable docker - Add your user to the
dockergroup to avoid usingsudoevery time:sudo usermod -aG docker $USER, then log out and back in
Pull and run the official hello-world image
Docker Hub hosts ready-to-use images. The hello-world image is tiny and designed for testing.
- Download it:
docker pull hello-world(optional —docker rundoes this automatically if missing) - Run it:
docker run hello-world - You’ll see a short message like “Hello from Docker!” — that means it worked
Check what’s running and clean up
Verify your container ran and exited successfully.
- List all containers (including stopped ones):
docker ps -a - You’ll see one entry with status “Exited (0)” — that’s expected for
hello-world - No need to remove it manually — it’s harmless. But if you want to clear old containers:
docker rm $(docker ps -aq)
What just happened?
The hello-world image contains a minimal executable that prints a message and exits. Docker launched a lightweight, isolated environment (a container), ran the program inside it, and shut down cleanly.
That’s it — you’ve successfully run your first container. No code to write, no server to configure. Just one command, and Docker handled the rest.
Basically it’s not complex — but easy to overlook the setup step or forget to add your user to the docker group.
The above is the detailed content of How to run your first Docker container on Linux? (Hello World Example). For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20518
7
13631
4
How to install Redis cluster on Linux_Linux distributed cache deployment solution [Advanced]
Feb 08, 2026 pm 07:39 PM
The Redis6 cluster must be created with redis-cli--cluster. It requires a minimum of 3 masters and 3 slaves, a total of 6 nodes. The client port and the corresponding cluster bus port (10000) must be opened. Correct configuration but blocked ports is a common cause of failure.
How to import SQL files in mysql_mysql SQL file import method
Feb 09, 2026 pm 05:24 PM
The most common and reliable way to import SQL files into MySQL is the command line tool mysql, which supports cross-platform, high efficiency and stability, and is suitable for files of all sizes. It can also be executed in the client through the source command, or using graphical tools such as phpMyAdmin and MySQL Workbench.
How to check system vulnerabilities in Linux_Linux installation and use of security scanning tools [Plan]
Feb 08, 2026 pm 08:22 PM
Linux systems need to use third-party tools for security scanning; lynis is suitable for lightweight local auditing, openvas must be deployed with Docker, nmap and nessus cannot be automatically connected, and the effectiveness of scanning depends on credentials, settings and feed updates.
How to check the MAC address of the network card in Linux_Linux obtains the physical network card information [Notes]
Feb 08, 2026 pm 08:25 PM
The most reliable way is to use the iplinkshow command, because it is compatible with old and new kernels, has clear output, and does not confuse virtual interfaces; the MAC address is located after the link/ether line and can be accurately extracted with grep.
How to choose the version when installing mysql_mysql version selection suggestions
Feb 09, 2026 pm 05:57 PM
The key is not "latest" but "matching": the corresponding MySQL version needs to be selected according to the application framework (such as SpringBoot2.x/3.x, Django4.2) and driver version to avoid compatibility issues such as authentication plug-ins, sorting rules, and proxy tools. For production environments, the 8.0.33LTS version is preferred.
How to check the kernel version in Linux_Linux query system kernel uname command [Basic]
Feb 08, 2026 pm 07:48 PM
uname-r is the most accurate and quick way to obtain the current kernel version number. It only outputs the release field such as 6.1.0-22-amd64, without redundant information, which is convenient for script parsing; other commands such as uname-v, uname-a or /proc/version have their own uses but are not specifically used for version extraction.
How to install the GCC compiler on Linux_Essential environment for Linux source code compilation [Tutorial]
Feb 08, 2026 pm 08:28 PM
Using sudoaptinstallbuild-essential is the fastest under Ubuntu/Debian. It automatically installs gcc, g, make, libc6-dev, etc.; only installing gcc will report an error that stdio.h does not exist due to a missing header file.
How to clean up system logs in Linux_Linux tips for releasing varlog space [Essence]
Feb 08, 2026 pm 07:36 PM
The main reason why /var/log fills up the disk is that journalctl logs grow indefinitely, logrotate fails, or application logs are not cut. You need to use journalctl --vacuum-size or configure journald.conf restrictions, check logrotate permissions and rules, and clean up hidden log directories such as apt and unattended-upgrades.





