centos7安裝docker最新入門
first 驗證核心
uname -r 檢視核心版本是否高於3.10 筆者的測試機器為3.10.0-862.el7.x86_64
第一個警告
切勿在沒有配置docker yum' 源的情況下直接使用yum命令安裝docker
由於centos7剛好滿足最低核心的要求但是核心版本較低,部分功能(如 overlay2儲存層驅動) 無法使用,,並且部分功能不穩定
開始安裝
解除安裝舊版本
$ sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine
使用yum安裝
執行以安裝以下依賴包
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
由於網路超慢,使用國內源
# This is 中國科技大學開源映象站 $ sudo yum-config-manager \ --add-repo \ https://mirrors.ustc.edu.cn/docker/linux/centos/docker-ce.repo #這是官方源,不推薦 #$ sudo yum-config-manager \ # --add-repo \ # https://download.docker.com/linux/centos/docker-ce.repo
Optional: Enable the edge and test repositories. These repositories are included in the docker.repo file above but are disabled by default. You can enable them alongside the stable repository.(選擇你需要的docker版本)
$ sudo yum-config-manager --enable docker-ce-edge $ sudo yum-config-manager --enable docker-ce-test
You can disable the edge or test repository by running theyum-config-manager command with the --disable flag. To re-enable it, use the --enable flag. The following command disables the edgerepository.(預設禁用…執行啟用…)
$ sudo yum-config-manager --disable docker-ce-edge
Note: Starting with Docker 17.06, stable releases are also pushed to the edge and test repositories.
INSTALL DOCKER CE
1.Install the latest version of Docker CE, or go to the next step to install a specific version:
# This first step means clean yum cache
$ sudo yum makecache fast
$ sudo yum install docker-ce
不想麻煩,那麼試試指令碼安裝吧
Install using the convenience script
- The scripts require root or sudo privileges to run. Therefore, you should carefully examine and audit the scripts before running them.
- The scripts attempt to detect your Linux distribution and version and configure your package management system for you. In addition, the scripts do not allow you to customize any installation parameters. This may lead to an unsupported configuration, either from Docker’s point of view or from your own organization’s guidelines and standards.
- The scripts install all dependencies and recommendations of the package manager without asking for confirmation. This may install a large number of packages, depending on the current configuration of your host machine.
- The script does not provide options to specify which version of Docker to install, and installs the latest version that is released in the “edge” channel.
- Do not use the convenience script if Docker has already been installed on the host machine using another mechanism.
This example uses the script at get.docker.com to install the latest release of Docker CE on Linux. To install the latest testing version, use test.docker.cominstead. In each of the commands below, replace each occurrence of get with test
Warning:
Always examine scripts downloaded from the internet before running them locally.
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
Docker is installed but not started. The docker group is created, but no users are added to the group.
If you would like to use Docker as a non-root user, you should now consider adding your user to the “docker” group with something like:
sudo usermod -aG docker your-user
Remember to log out and back in for this to take effect!(記住退出並返回使其生效)
Warning:
Adding a user to the “docker” group grants the ability to run containers which can be used to obtain root privileges on the docker host. Refer to Docker Daemon Attack Surface for more information.
sudo systemctl start docker
exit
Test Docker installation
docker run hello-world
#If you see the following information, congratulations
this message shows that you installation apperas to be working correctly
Uninstall Docker CE
- Uninstall the Docker package:
$ sudo yum remove docker-ce - Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:
$ sudo rm -rf /var/lib/docker
You must delete any edited configuration files manually.
.啟動 systemctl start docker
.檢視狀態 systemctl status docker
.檢視docker資訊 docker info
幫助 docker pull --help
docker基礎操作
Part 1:Orientation
Welcome! We are excited that you want to learn Docker.
Docker concepts
Docker is a platform for developers and sysadmins to develop, deploy, and runapplications with containers. The use of Linux containers to deploy applications is called containerization. Containers are not new, but their use for easily deploying applications is.
Containerization is increasingly popular because containers are:
- Flexible: Even the most complex applications can be containerized.
- Lightweight: Containers leverage and share the host kernel.
- Interchangeable: You can deploy updates and upgrades on-the-fly.
- Portable: You can build locally, deploy to the cloud, and run anywhere.
- Scalable: You can increase and automatically distribute container replicas.
- Stackable: You can stack services vertically and on-the-fly.
Containers and virtual machines
A container runs natively on Linux and shares the kernel of the host machine with other containers. It runs a discrete process, taking no more memory than any other executable, making it lightweight.
By contrast, a virtual machine (VM) runs a full-blown “guest” operating system with virtual access to host resources through a hypervisor. In general, VMs provide an environment with more resources than most applications need.
Test docker version
Run docker --version and ensure that you have a supported version of Docker
docker --version
Docker version 18.06.1-ce, build e68fc7a
Run docker info or (docker version without --) to view even more details about your docker installation:
docker info
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 3
Server Version: 18.06.1-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
...
To avoid permission errors (and the use of sudo), add your user to the docker group. Read more.
Test Docker installation
驗證安裝
-
Test that your installation works by running the simple Docker image, hello-world:
docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
列出映象