The steps to install Docker include updating the system and installing dependencies, adding GPG keys and repositories, installing the Docker engine, configuring user permissions, and testing the run. 1. First execute sudo apt update and sudo apt upgrade to update the system; 2. Install apt-transport-https, ca-certificates and other dependency packages; 3. Add the official GPG key and configure the warehouse source; 4. Run sudo apt install to install docker-ce, docker-ce-cli and containerd.io; 5. Add the user to the docker group to avoid using sudo; 6. Finally, verify that the installation is successful through docker run hello-world. Attention to details at each step, such as updating the warehouse or adjusting permission settings to ensure smooth installation and operation.
Installing Docker is actually not too difficult, but for people who are new to Linux, they may be a little dizzy by various commands and dependencies. In fact, as long as you operate according to the officially recommended method, the whole process will be quite smooth.
Update the system and install the necessary dependencies
Before you start installing, make sure your system is up to date, which can avoid many compatibility issues. Execute the following command to update the package list and upgrade the installed software:
-
sudo apt update
-
sudo apt upgrade
If you are using a Debian-based distribution (such as Ubuntu), you also need to install some necessary dependencies so that apt can use the repository via HTTPS:
-
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
Although this step seems simple, many people tend to ignore it. As a result, they encounter certificate errors or problems such as in the subsequent steps or the source cannot be connected.
Add Docker official GPG keys and repositories
To ensure that the downloaded Docker is officially and has not been tampered with, you need to add its GPG key:
-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Then add the stable version of the repository source. Note that the commands should be adjusted according to the distribution you are using. For example, Ubuntu 20.04 or 22.04 can use the following sentence:
-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Remember to run sudo apt update
again after this step is completed, otherwise the system will not recognize the newly added repository.
Install Docker Engine
Now you can officially install Docker. Run the following command:
-
sudo apt install docker-ce docker-ce-cli containerd.io
This command installs the Docker engine (docker-ce), command line tools (docker-ce-cli), and containerd runtime. After the installation is completed, you can use docker --version
to see if the version number is successfully output.
By default, Docker needs to be run with sudo
. To avoid adding sudo every time, you can add the current user to the docker user group:
-
sudo usermod -aG docker $USER
Remember to log in again after logging out, and this setting will take effect.
Test whether Docker is running normally
The easiest way to test is to run a hello-world container:
-
docker run hello-world
If everything works, you will see a welcome message saying that Docker has successfully up and running a container.
Sometimes, if your system firewall or SELinux is set up relatively strictly, the container may not function properly. At this time, you can try temporarily closing the firewall or checking the log to troubleshoot problems.
Basically that's it. The whole process is not complicated, but each step has some small details to pay attention to.
The above is the detailed content of How to install Docker on Linux. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

When encountering Docker problems, you should first locate the problem, which is problems such as image construction, container operation or network configuration, and then follow the steps to check. 1. Check the container log (dockerlogs or docker-composelogs) to obtain error information; 2. Check the container status (dockerps) and resource usage (dockerstats) to determine whether there is an exception due to insufficient memory or port problems; 3. Enter the inside of the container (dockerexec) to verify the path, permissions and dependencies; 4. Review whether there are configuration errors in the Dockerfile and compose files, such as environment variable spelling or volume mount path problems, and recommend that cleanbuild avoid cache dryness

The steps to install Docker include updating the system and installing dependencies, adding GPG keys and repositories, installing the Docker engine, configuring user permissions, and testing the run. 1. First execute sudoaptupdate and sudoaptupgrade to update the system; 2. Install apt-transport-https, ca-certificates and other dependency packages; 3. Add the official GPG key and configure the warehouse source; 4. Run sudoaptinstall to install docker-ce, docker-ce-cli and containerd.io; 5. Add the user to the docker group to avoid using sudo; 6. Finally, dock

To manage Linux user groups, you need to master the operation of viewing, creating, deleting, modifying, and user attribute adjustment. To view user group information, you can use cat/etc/group or getentgroup, use groups [username] or id [username] to view the group to which the user belongs; use groupadd to create a group, and use groupdel to specify the GID; use groupdel to delete empty groups; use usermod-aG to add users to the group, and use usermod-g to modify the main group; use usermod-g to remove users from the group by editing /etc/group or using the vigr command; use groupmod-n (change name) or groupmod-g (change GID) to modify group properties, and remember to update the permissions of relevant files.

Adjusting kernel parameters (sysctl) can effectively optimize system performance, improve network throughput, and enhance security. 1. Network connection: Turn on net.ipv4.tcp_tw_reuse to reuse TIME-WAIT connection to avoid enabling tcp_tw_recycle in NAT environment; appropriately lower net.ipv4.tcp_fin_timeout to 15 to 30 seconds to speed up resource release; adjust net.core.somaxconn and net.ipv4.tcp_max_syn_backlog according to the load to cope with the problem of full connection queue. 2. Memory management: reduce vm.swappiness to about 10 to reduce

To restart the service managed by systemctl in Linux, 1. First use the systemctlstatus service name to check the status and confirm whether it is necessary to restart; 2. Use the sudosystemctlrestart service name command to restart the service, and ensure that there is administrator privileges; 3. If the restart fails, you can check whether the service name is correct, whether the configuration file is wrong, or whether the service is installed successfully; 4. Further troubleshooting can be solved by viewing the log journalctl-u service name, stopping and starting the service first, or trying to reload the configuration.

The three modes of SELinux are enforcing, permissive and disabled. You can use sestatus or getenforce commands to view the current status; you can use setenforce0 (permissive) or setenforce1 (enforcing) for temporary switching modes, but they can be invalid after restart; permanent changes require editing /etc/selinux/config file and restarting the system; it is recommended to use permissive mode to take into account error troubleshooting and security. Logs should be checked before operation, compatibility should be considered, and file context labels may need to be restored after switching.

To make the command run in the background, there are the following methods and precautions: 1. Add & at the end of the command to put the task in the background to execute, but closing the terminal may cause the task to terminate; 2. Use the nohup command to combine & to avoid the process being interrupted due to terminal shutdown, and the default output will be redirected to the nohup.out file; 3. You can use jobs to view the background tasks, fg and bg switch the front and backstage status of the task, and kill terminates the task; if the task is not in the current shell session, ps and kill can be used to manage the process.

Bash scripts handle command line parameters through special variables. Use $1, $2, etc. to get positional parameters, where $0 represents the script name; iterates through "$@" or "$*", the former retains space separation, and the latter is merged into a single string; use getopts to parse options with parameters (such as -a, -b:value), where the option is added to indicate the parameter value; at the same time, pay attention to referring to variables, using shift to move the parameter list, and obtaining the total number of parameters through $#.
