docker 入坑1
本文是记录一下学习docker的过程,希望可以帮助到入门的朋友。
系统:ubuntu16.04
docker:18.09
打开官网:https://docs.docker.com/install/linux/docker-ce/ubuntu/
os requirements
to install docker engine - community, you need the 64-bit version of one of these ubuntu versions:
- disco 19.04
- cosmic 18.10
- bionic 18.04 (lts)
- xenial 16.04 (lts)
docker engine - community is supported on
x86_64
(oramd64
),armhf
,arm64
,s390x
(ibm z), andppc64le
(ibm power) architectures.
查看我们的系统是否符合最新版docker安装的要求:
1 mantishell@zkl:~$ uname -a 2 linux zkl 4.15.0-55-generic #60~16.04.2-ubuntu smp thu jul 4 09:03:09 utc 2019 x86_64 x86_64 x86_64 gnu/linux 3 mantishell@zkl:~$ lsb_release -a 4 no lsb modules are available. 5 distributor id: ubuntu 6 description: ubuntu 16.04.6 lts 7 release: 16.04 8 codename: xenial
符合最后一条:xenial 16.04 (lts)
如果不符合,怎么办呢?不要灰心,可以安装历史版本。官网也有说明。
install docker engine - community
you can install docker engine - community in different ways, depending on your needs:
most users set up docker’s repositories and install from them, for ease of installation and upgrade tasks. this is the recommended approach.
some users download the deb package and and manage upgrades completely manually. this is useful in situations such as installing docker on air-gapped systems with no access to the internet.
in testing and development environments, some users choose to use automated to install docker.
install using the repository
before you install docker engine - community for the first time on a new host machine, you need to set up the docker repository. afterward, you can install and update docker from the repository.
set up the repository
update the
apt
package index:$ sudo apt-get updateinstall packages to allow
apt
to use a repository over https:$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-commonadd docker’s official gpg key:
$ curl -fssl https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -verify that you now have the key with the fingerprint
9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88
, by searching for the last 8 characters of the fingerprint.$ sudo apt-key fingerprint 0ebfcd88 pub rsa4096 2017-02-22 [scea] 9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88 uid [ unknown] docker release (ce deb) <docker@docker.com> sub rsa4096 2017-02-22 [s]use the following command to set up the stable repository. to add the nightly or test repository, add the word
nightly
ortest
(or both) after the wordstable
in the commands below. learn about nightly and test channels.note: the
lsb_release -cs
sub-command below returns the name of your ubuntu distribution, such asxenial
. sometimes, in a distribution like linux mint, you might need to change$(lsb_release -cs)
to your parent ubuntu distribution. for example, if you are usinglinux mint tessa
, you could usebionic
. docker does not offer any guarantees on untested and unsupported ubuntu distributions.$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"install docker engine - community
update the
apt
package index.$ sudo apt-get updateinstall the latest version of docker engine - community and containerd, or go to the next step to install a specific version:
$ sudo apt-get install docker-ce docker-ce-cli containerd.iogot multiple docker repositories?
if you have multiple docker repositories enabled, installing or updating without specifying a version in the
apt-get install
orapt-get update
command always installs the highest possible version, which may not be appropriate for your stability needs.to install a specific version of docker engine - community, list the available versions in the repo, then select and install:
a. list the versions available in your repo:
$ apt-cache madison docker-ce docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 packages docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 packages docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 packages docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 packages ...b. install a specific version using the version string from the second column, for example,
5:18.09.1~3-0~ubuntu-xenial
.$ sudo apt-get install docker-ce=<version_string> docker-ce-cli=<version_string> containerd.ioverify that docker engine - community is installed correctly by running the
hello-world
image.$ sudo docker run hello-worldthis command downloads a test image and runs it in a container. when the container runs, it prints an informational message and exits.
docker engine - community is installed and running. the
docker
group is created but no users are added to it. you need to usesudo
to run docker commands. continue to linux postinstall to allow non-privileged users to run docker commands and for other optional configuration steps.upgrade docker engine - community
to upgrade docker engine - community, first run
sudo apt-get update
, then follow the , choosing the new version you want to install.install from a package
if you cannot use docker’s repository to install docker engine - community, you can download the
.deb
file for your release and install it manually. you need to download a new file each time you want to upgrade docker.
go to , choose your ubuntu version, browse to
pool/stable/
, chooseamd64
,armhf
,arm64
,ppc64el
, ors390x
, and download the.deb
file for the docker engine - community version you want to install.note: to install a nightly package, change the word
stable
in the url tonightly
. learn about nightly and test channels.install docker engine - community, changing the path below to the path where you downloaded the docker package.
$ sudo dpkg -i /path/to/package.debthe docker daemon starts automatically.
verify that docker engine - community is installed correctly by running the
hello-world
image.$ sudo docker run hello-worldthis command downloads a test image and runs it in a container. when the container runs, it prints an informational message and exits.
docker engine - community is installed and running. the
docker
group is created but no users are added to it. you need to usesudo
to run docker commands. continue to post-installation steps for linux to allow non-privileged users to run docker commands and for other optional configuration steps.upgrade docker engine - community
to upgrade docker engine - community, download the newer package file and repeat the , pointing to the new file.
install using the convenience script
docker provides convenience scripts at and for installing edge and testing versions of docker engine - community into development environments quickly and non-interactively. the source code for the scripts is in the . using these scripts is not recommended for production environments, and you should understand the potential risks before you use them:
- the scripts require
root
orsudo
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 to install the latest release of docker engine - community on linux. to install the latest testing version, use instead. in each of the commands below, replace each occurrence of
get
withtest
.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 <output truncated>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-userremember to log out and back in for this to take effect!
warning:
adding a user to the “docker” group grants them 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.
docker engine - community is installed. it starts automatically on
deb
-based distributions. onrpm
-based distributions, you need to start it manually using the appropriatesystemctl
orservice
command. as the message indicates, non-root users can’t run docker commands by default.upgrade docker after using the convenience script
if you installed docker using the convenience script, you should upgrade docker using your package manager directly. there is no advantage to re-running the convenience script, and it can cause issues if it attempts to re-add repositories which have already been added to the host machine.
uninstall docker engine - community
uninstall the docker engine - community package:
$ sudo apt-get purge docker-ceimages, 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/dockeryou must delete any edited configuration files manually.
上面是官方给的步骤,相信大家按照步骤一步步进行,也能搭建起来。这里呢我记录一下,我的操作步骤:
- update the apt package index:
$ sudo apt-get update
- install packages to allow apt to use a repository over https:
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
- add docker`s offical gpg key:
$ curl -fssl https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- set up the repository
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" $ sudo apt-get update
- install the latest version of docker engine - community and containerd, or go to the next step to install a specific version:
$ sudo apt-get install docker docker-compose
- to install a specific version of docker engine - community, list the available versions in the repo, then select and install:
- list the versions available in your repo:
$ apt-cache madison docker-ce
- install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial
$ sudo apt-get install docker-ce=<version_string> docker-ce-cli=<version_string> containerd.io $ sudo apt-get install docker-ce=5:18.09.0~3-0~ubuntu-xenial docker-ce-cli=5:18.09.0~3-0~ubuntu-xenial containerd.io
- list the versions available in your repo:
- verify that docker engine - community is installed correctly by running the hello-world image.
$ sudo docker run hello-world
推荐阅读
-
docker 入坑1
-
微信入坑第一弹 微信公众号第一篇推文 第一财经微信公众号 微信公众号第一条消
-
Alios-Things入坑记之rtl8710bn初体验
-
SpringBoot入坑笔记之spring-boot-starter-web 配置文件的使用
-
SpringBoot入坑笔记之spring-boot-starter-web 配置文件的使用
-
RxJava 1升级到RxJava 2过程中踩过的一些“坑”
-
浅谈Android Studio3.0更新之路(遇坑必入)
-
RxJava 1升级到RxJava 2过程中踩过的一些“坑”
-
.NET 微服务 1. Docker 容器简介和选择
-
Centos7安装docker compse踩过的坑及解决方法