Ubuntu Server下docker实战 01: 安装docker
程序员文章站
2022-06-26 10:02:07
本系列文章主旨在于使用docker来搭建实际可用的基础服务,具体到每一步的操作和设置。 关于docker的原理、前世今生的内容,园子里已经有太多的文章了,此处就不再赘述。 要使用docker,当然第一步就是把它装到机器上,今天第一篇就讲docker自身的安装。 本文使用的服务器配置如下: CPU: ......
本系列文章主旨在于使用docker来搭建实际可用的基础服务,具体到每一步的操作和设置。
关于docker的原理、前世今生的内容,园子里已经有太多的文章了,此处就不再赘述。
要使用docker,当然第一步就是把它装到机器上,今天第一篇就讲docker自身的安装。
本文使用的服务器配置如下:
cpu: 8核
内存: 16g
硬盘: 50g+400g双硬盘
系统: ubuntu 18.04.1 lts
安装步骤如下:
1. 更新ubuntu所有组件到最新
sudo apt-get update sudo apt-get upgrade
2. 安装必备软件
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
3. 添加密钥
curl -fssl https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo apt-key fingerprint 0ebfcd88
4. 添加docker源仓库
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
5. 更新仓库列表
sudo apt-get update
6. 安装最新版本 docker
sudo apt-get install docker-ce
安装过程显示如下,如果网络顺畅的话,应该能够很顺利的安装完成
reading package lists... done building dependency tree reading state information... done the following additional packages will be installed: aufs-tools cgroupfs-mount libltdl7 pigz the following new packages will be installed: aufs-tools cgroupfs-mount docker-ce libltdl7 pigz 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded. need to get 40.2 mb/40.4 mb of archives. after this operation, 199 mb of additional disk space will be used. do you want to continue? [y/n] get:1 https://download.docker.com/linux/ubuntu bionic/stable amd64 docker-ce amd64 18.06.1~ce~3-0~ubuntu [40.2 mb] fetched 3,431 kb in 1min 57s (29.3 kb/s) selecting previously unselected package pigz. (reading database ... 88421 files and directories currently installed.) preparing to unpack .../archives/pigz_2.4-1_amd64.deb ... unpacking pigz (2.4-1) ... selecting previously unselected package aufs-tools. preparing to unpack .../aufs-tools_1%3a4.9+20170918-1ubuntu1_amd64.deb ... unpacking aufs-tools (1:4.9+20170918-1ubuntu1) ... selecting previously unselected package cgroupfs-mount. preparing to unpack .../cgroupfs-mount_1.4_all.deb ... unpacking cgroupfs-mount (1.4) ... selecting previously unselected package libltdl7:amd64. preparing to unpack .../libltdl7_2.4.6-2_amd64.deb ... unpacking libltdl7:amd64 (2.4.6-2) ... selecting previously unselected package docker-ce. preparing to unpack .../docker-ce_18.06.1~ce~3-0~ubuntu_amd64.deb ... unpacking docker-ce (18.06.1~ce~3-0~ubuntu) ... setting up aufs-tools (1:4.9+20170918-1ubuntu1) ... processing triggers for ureadahead (0.100.0-20) ... setting up cgroupfs-mount (1.4) ... processing triggers for libc-bin (2.27-3ubuntu1) ... processing triggers for systemd (237-3ubuntu10.3) ... setting up libltdl7:amd64 (2.4.6-2) ... processing triggers for man-db (2.8.3-2) ... setting up pigz (2.4-1) ... setting up docker-ce (18.06.1~ce~3-0~ubuntu) ... created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service. created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket. processing triggers for ureadahead (0.100.0-20) ... processing triggers for libc-bin (2.27-3ubuntu1) ... processing triggers for systemd (237-3ubuntu10.3) ...
至此,docker安装完成,下面对docker做一些基本配置
7. 设置docker拉取镜像使用的代理(本步骤可选,根据实际需要设置)
# 创建配置目录 mkdir -p /etc/systemd/system/docker.service.d # 编辑配置文件 vi /etc/systemd/system/docker.service.d/http-proxy.conf
插入如下内容
[service] environment="http_proxy=http://192.168.0.158:3128/"
保存退出,重启docker
systemctl daemon-reload systemctl restart docker
查看配置结果
systemctl show --property=environment docker
8. 来一个hello world
sudo docker pull hello-world sudo docker run hello-world
如果配置正常的话将显示如下结果
using default tag: latest latest: pulling from library/hello-world d1725b59e92d: pull complete digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 status: downloaded newer image for hello-world:latest
hello from docker! this message shows that your installation appears to be working correctly. to generate this message, docker took the following steps: 1. the docker client contacted the docker daemon. 2. the docker daemon pulled the "hello-world" image from the docker hub. (amd64) 3. the docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. the docker daemon streamed that output to the docker client, which sent it to your terminal. to try something more ambitious, you can run an ubuntu container with: $ docker run -it ubuntu bash share images, automate workflows, and more with a free docker id: https://hub.docker.com/ for more examples and ideas, visit: https://docs.docker.com/get-started/
推荐阅读
-
Ubuntu下安装Docker教程
-
Docker-Compose简介与Ubuntu Server 上安装Compose
-
Ubuntu下Docker CE的安装
-
[视频教程] 如何在docker环境下的纯净ubuntu系统中安装最新版nginx
-
[原创] Ubuntu 下 Docker 安装及使用简明教程 - 制作 Spring Boot 应用镜像
-
ubuntu16.04下安装部署mesos+marathon+docker
-
Ubuntu Server 16.04 安装Docker环境
-
树莓派4b ubuntu19 server 安装docker-ce的安装步骤
-
Ubuntu Server下docker实战 01: 安装docker
-
docker在ubuntu14.04下的安装步骤