Ubuntu16.04 64bits安装docker

首先docker需要64bits的机器,32bits的无法安装。

安装最简单的方法是:sudo apt-get update   sudo apt-get install docker
但这样安装,以后升级可能会升级不了,因为ubuntu的下没有docker相关的源。

更新安装包信息,确保 APT 使用 https 协议,同时CA 证书已经被安装.

$ sudo apt-get update
 $ sudo apt-get install apt-transport-https ca-certificates

添加新的GPGkey

$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

找到合适你的Ubuntu操作系统的键,这个键决定APT将搜索哪个包

用编辑器打开 /etc/apt/sources.list.d/docker.list添加下面这句,如果不存在docker.list新建一个再添加。

deb https://apt.dockerproject.org/repo ubuntu-xenial main

注意:docker没有为所有的架构提供包,Binary artifacts are built nightly,你可以从https://master.dockerproject.org. 处下载下来。在一个多架构的系统上安装docker,为键添加一个[arch=]条款。更多细节参考Debian Multiarch维基百科。

更新APT 软件包索引

$ sudo apt-get update

清除旧的repo if it exists

$ sudo apt-get purge lxc-docker

至此,你可以 使用命令apt-get upgrade,APT 从新代码库拉取代码.

这里记得upgrade一下,否则安装时会遇到无法安装,我在第一次安装时由于没有upgrade,提示安装相关包失败.

某些Ubuntu版本需要的前置操作

Ubuntu Xenial 16.04[LTS]  Ubuntu Trusty 14.04[LTS]
   这两个版本记得安装linux-iamge-extra-*的kernel包。这个包允许你使用aufs存储驱动。

$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

以上前期准备做完后,就可以安装docker

1) 更新APT包索引:sudo apt-get update
2) 安装docker:sudo apt-get install docker-engine
3) 开启docker后天进程:sudo service docker start
4) 校验docker是否安装成功:sudo docker run hello-world
这个命令会下载一个测试镜像,并且运行在一个容器中。当容器运行时,他会打印一些信息,并且退出。

下面是安装成功后,启动docker服务,下载hello-world测试镜像的log记录:

jack@jack-VirtualBox:~$ sudo service docker start [sudo] password for jack: jack@jack-VirtualBox:~$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 9a0669468bf7: Pull complete Digest: sha256:cf2f6d004a59f7c18ec89df311cf0f6a1c714ec924eebcbfdd759a669b90e711 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. 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://cloud.docker.com/ For more examples and ideas,visit: https://docs.docker.com/engine/userguide/

可选配置

创建一个docker组

docker后台进程是绑定的Unix的socket而不是TCP端口。默认情况下,Unix的socket属于用户root,其它用户要使用要通过sudo命令。由于这个原因,docker daemon通常使用root用户运行。
为了避免使用sudo当你使用docker命令的时候,创建一个Unix组名为docker并且添加用户。当docker daemon启动,它会分配Unix socket读写权限给所属的docker组。
注意:docker组不等价于用户root,如果想要知道的更多关于安全影响,查看docker daemon attack surface

  sudo groupadd docker //在ubuntu16上不需要另外创建docker助,默认在安装docker是就已经建好了,可以用cat /etc/group查看下有无docker组

  sudo usermod -aG docker $USER

退出再重进,确保该用户有正确的权限。
This ensures your user is running with the correct permissions.

确认不使用sudo可以运行docker.

$ docker run hello-world

如果提示失败信息与下面相似:

Cannot connect to the Docker daemon. Is ‘docker daemon’ running on this host?
检查 DOCKER_HOST 环境变量 没有设置shell. 如果这样,重置他.

调整内存和交换区计算

When users run Docker,they may see these messages when working with an image:

WARNING: Your kernel does not support cgroup swap limit. WARNING: Your
kernel does not support swap limit capabilities. Limitation discarded.
To prevent these messages,enable memory and swap accounting on your system. Enabling memory and swap accounting does induce both a memory overhead and a performance degradation even when Docker is not in use. The memory overhead is about 1% of the total available memory. The performance degradation is roughly 10%.

To enable memory and swap on system using GNU GRUB (GNU GRand Unified Bootloader),do the following:

Log into Ubuntu as a user with sudo privileges.

Edit the /etc/default/grub file.

Set the GRUB_CMDLINE_LINUX value as follows:

GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
Save and close the file.

Update GRUB.

$ sudo update-grub
Reboot your system.

当用户运行docker时,他们可能在使用一个镜像时看见下面的信息:

  WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.

  为了阻止这些信息,在你的系统中启用内存和交换区计算。这个操作会导致即便docker没有使用也有内存开销以及性能下降。内存开销大概是总内存的1%。性能降低了大约10%。

  修改/etc/default/grub文件。vi或者vim命令都行,设置GRUB_CMDLINE_LINUX的值,如下:GRUB_CMDLINE_LINUX=”cgroup_enable=memory swapaccount=1”。保存文件并关闭。sudo update-grub更新启动项。reboot重启你的系统。

启动UFW转发

If you use UFW (Uncomplicated Firewall) on the same host as you run Docker,you’ll need to do additional configuration. Docker uses a bridge to manage container networking. By default,UFW drops all forwarding traffic. As a result,for Docker to run when UFW is enabled,you must set UFW’s forwarding policy appropriately.

Also,UFW’s default set of rules denies all incoming traffic. If you want to reach your containers from another host allow incoming connections on the Docker port. The Docker port defaults to 2376 if TLS is enabled or 2375 when it is not. If TLS is not enabled,communication is unencrypted. By default,Docker runs without TLS enabled.

To configure UFW and allow incoming connections on the Docker port:

Log into Ubuntu as a user with sudo privileges.

Verify that UFW is installed and enabled.

$ sudo ufw status
Open the /etc/default/ufw file for editing.

$ sudo nano /etc/default/ufw
Set the DEFAULT_FORWARD_POLICY policy to:

DEFAULT_FORWARD_POLICY="ACCEPT"
Save and close the file.

Reload UFW to use the new setting.

$ sudo ufw reload
Allow incoming connections on the Docker port.

$ sudo ufw allow 2375/tcp

  当你运行docker时,在同一台主机上使用UFW(Uncomplicated Firewall) ,你需要额外的配置。docker使用桥接方式来管理容器的网络。默认情况下,UFW废弃所有的转发流量。因此,docker运行时UFW可以使用,你必须设置合适UFW的转发规则。

  UFW默认配置规则拒绝了所有传入流量。如果你想要从另一个主机到达你的容器需要允许连接docker的端口。docker的默认端口是2376如果TLS启用,如果没有启动则是2375,会话是不加密的。默认情况,docker运行在没有TLS启动的情况下。

  为了配置UFW并且允许进入的连接docker端口:

  检查UFW是否安装并启用:sudo ufw status

  打开/etc/default/ufw文件并编辑:sudo nano /etc/default/ufw

  设置DEFAULT_FORWARD_POLICY:DEFAULT_FORWARD_POLICY=”ACCEPT”

  保存退出并重启使用新的设置:sudo ufw reload

  允许所有的连接到docker端口:sudo ufw allow 2375/tcp

为使用docker配置DNS服务器

Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use127.0.0.1 as the default nameserver in /etc/resolv.conf file. The NetworkManager also sets up dnsmasq to use the real DNS servers of the connection and sets up nameserver 127.0.0.1 in /etc/resolv.conf.

When starting containers on desktop machines with these configurations,Docker users see this warning:

WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers
can't use it. Using default external servers : [8.8.8.8 8.8.4.4]
The warning occurs because Docker containers can’t use the local DNS nameserver. Instead,Docker defaults to using an external nameserver.

To avoid this warning,you can specify a DNS server for use by Docker containers. Or,you can disable dnsmasq in NetworkManager. Though,disablingdnsmasq might make DNS resolution slower on some networks.

The instructions below describe how to configure the Docker daemon running on Ubuntu 14.10 or below. Ubuntu 15.04 and above use systemd as the boot and service manager. Refer to control and configure Docker with systemd to configure a daemon controlled by systemd.

To specify a DNS server for use by Docker:

Log into Ubuntu as a user with sudo privileges.

Open the /etc/default/docker file for editing.

$ sudo nano /etc/default/docker
Add a setting for Docker.

DOCKER_OPTS="--dns 8.8.8.8"
Replace 8.8.8.8 with a local DNS server such as 192.168.1.1. You can also specify multiple DNS servers. Separated them with spaces,for example:

--dns 8.8.8.8 --dns 192.168.1.1
Warning: If you’re doing this on a laptop which connects to various networks,make sure to choose a public DNS server.

Save and close the file.

Restart the Docker daemon.

$ sudo service docker restart


Or,as an alternative to the previous procedure,disable dnsmasq in NetworkManager (this might slow your network).

Open the /etc/NetworkManager/NetworkManager.conf file for editing.

$ sudo nano /etc/NetworkManager/NetworkManager.conf
Comment out the dns=dnsmasq line:

dns=dnsmasq
保存并关闭.

重启NetworkManager 和 Docker.

$ sudo restart network-manager
$ sudo restart docker

 系统运行桌面的Ubuntu或者Ubuntu衍生产品通常使用127.0.0.1作为默认的nameserver文件/etc/resolv.conf文件中。NetworkManager也通常设置dnsmasq nameserver 127.0.0.1在/etc/resolv.conf。

  当在桌面机器运行容器,使用这些配置时,docker的使用者会看见这些警告:

  WARNING: Local (127.0.0.1) DNS resolver found in resolv.conf and containers can’t use it. Using default external servers : [8.8.8.8 8.8.4.4]

  这个警告发生是因为docker容器不能使用本地DNS命名服务器。此外docker默认使用一个额外的nameserver。

  为了避免这个警告,你可以在使用docker容器的时候指定一个DNS服务器。或者你可以禁用dnsmasq在NetworkManager中。但是,禁用会导致DNS协议在某些网络中变慢。

  下面的说明描述了如何在Ubuntu14.0或以下版本配置docker守护进程。Ubuntu15.04及之上的使用systemd用于启动项和服务管理。指导通过使用systemd来配置和控制一个守护进程。

  设置指定的DNS服务:

  打开/etc/default/docker文件并编辑:sudo nano /etc/default/docker,添加配置项:DOCKER_OPTS=”–dns 8.8.8.8”。将8.8.8.8用一个本地的DNS服务例如192.168.1.1替换。你也可以配置多个DNS服务器。用空格隔开它们,如:–dns 8.8.8.8 –dns 192.168.1.1。警告:当你在笔记本连接了不同网络的情况时做这些操作,确保选择一个公用的DNS服务器。保存文件并退出,重启docker守护进程:sudo service docker restart。

  或者另一个选择,禁用dnsmasq在网络管理器中,这可能导致你的网速变慢:

  打开/etc/NetworkManager/NetworkManager.conf文件,编辑它:sudo nano /etc/NetworkManager/NetworkManager.conf。找到行dns=dnsmasq,注释掉。保存关闭文件,重启网络管理器和docker.sudo restart network-manager sudo restart docker。
  

配置docker引导启动

Ubuntu uses systemd as its boot and service manager 15.04 onwards andupstart for versions 14.10 and below.

For 15.04 and up,to configure the docker daemon to start on boot,run

$ sudo systemctl enable docker
For 14.10 and below the above installation method automatically configuresupstart to start the docker daemon on boot

Ubuntu15.04之后使用systemd作为引导启动和服务管理,14.10及以下版本是upstart。15.04以上,需要配置docker守护进程boot启动,运行命令:sudo systemctl enable docker

  14.10及以下版本安装方法会自动配置upstart来启动docke daemon在boot。

升级卸载docker

升级:sudo apt-get upgrade docker-engine

  卸载:sudo apt-get purge docker-engine

  卸载及依赖:sudo apt-get autoremove –purge docker-engine

上述命令不会卸载images,containers,volumes或者用户自己创建的配置文件。你如果想删除这些东西,执行下面的命令:

  rm -rf /var/lib/docker

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预编译版,总体过程感觉还是挺简单的,但是由于在网上找的参考资料并没有和自己遇到的情况完全一样的,所以把自己的安装过程记录下来,方便和自己一样的后来人进行安装,同时也自己作个记录留作备忘。其实预编译版的CARLA本身几乎不用什么命令行进行安装,主要步骤只有解压缩和拷贝文件,和极少的命令行安装操作。但是相关依赖以及其它的CARLA所使用的一些工具需要一起安装好,下面一起来看看安装步骤吧。_ubuntu22.04安装carla
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载Ubuntu 20 安装包_ubuntu20下载
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装rally, pip3 install -r requirements.txt 时提示如下: 说明openssl 已安装。解决:1. pip3 install --upgrade pip , 结果输出如下 ..._error: command '/usr/bin/gcc' failed with exit code 1
文章浏览阅读1.1k次。自己刚踩坑装好的W11 WSL2 miniconda_wsl2 cuda
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standalone的,会有一点区别(不识别 下面的 -localhost no)上面的命令会在~/.vnc/目录下生成一个 passwd文件。具体端口号,可以查看vncserver -list返回结果中的RFB PROT。作用是vncserver启动的时候运行这些命令,把桌面程序启动起来。如果希望用某个用户比如 demo登录,就用su切换到这个用户。桌面版默认就已安装,服务器版需要手动安装,并启动。关闭某个会话可以用下面的命令。远程地址输入ip:port。查看全部的vnc会话。_ubuntu vncserver
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主要是连接一个远程的code-server服务,code-server服务安装在什么系统,调用的就是什么系统的环境,如这里使用ubuntu进行安装code-server,那使用的就是ubuntu环境,如需要go,python,java开发,需要在Ubuntu安装相关环境,创建的文件夹和项目也是在Ubuntu里面.这种方式其实在访问vscode的时候利于可以随时随地进行连接使用,且不受设备影响。
安装Ubuntu上超好用的终端Terminator。通过添加软件源、更新源、安装Terminator等步骤完成。
文章浏览阅读1.1k次,点赞83次,收藏74次。不要嫌弃Ubuntu的单调的终端界面啦,快来试试这些有意思的命令_ubuntu系统有趣的玩法
文章浏览阅读2.5k次。在ubuntu系统中,swap空间就是虚拟内存,所以考虑在磁盘空间富余的目录下设置虚拟内存swap文件,用来缓解内存不足的问题。通过上面的信息可以看到,/dev/vda2 目录下还剩余45G,那么就可以把swap文件生成在/dev/vda2目录下。在系统监控中发现,当数据库服务程序启动后,占用了大量内存空间,导致系统的剩余的内存往往只有几十MB。# bs 为块的大小,count 创建多少个块。# 执行命令后,删除创建的swap目录即可。#把生成的文件转换成 Swap 文件。2、创建一个swap文件。_ubuntu20修改swap大小
文章浏览阅读2.9k次,点赞2次,收藏10次。记录RV1126的SDK编译错误,以及解决处理_command exited with non-zero status 1
文章浏览阅读1.1w次,点赞22次,收藏101次。【记录】ubuntu20.04安装nvidia显卡驱动_ubuntu20.04安装nvidia显卡驱动
文章浏览阅读727次,点赞6次,收藏27次。在嵌入式Linux开发过程中,可能遇到uboot无法通过nfs服务从Ubuntu下载系统镜像(TTTTTT)的问题。如果你使用的是较新版本的Ubuntu,那么其**默认内核将不支持nfs2**!而**uboot仅支持到nfs2**,因此我们需要修改系统内核以及nfs配置文件,开启nfs2服务。**此问题非常棘手**,因为问题出现的时间太近,并且使用的人少。由于是2023年后才出现的问题,**chatgpt也无法解答**!本文参考网络上多篇博客资料,是解决此问题的最新办法。
ubuntu系统下安装软件的方法有多种,包括使用apt工具、deb软件包安装、源码编译安装以及通过软件中心安装。还有一种以 .run 后缀的软件包也可以在ubuntu系统下安装。具体的安装方法可以通过百度搜索来获取。
文章浏览阅读814次。本篇目的:Xubuntu如何安装pkg-configpkg-config是一个计算机软件包,用于帮助开发人员查找、定位和使用依赖库。它通常用于构建软件时,开发人员需要指定程序所依赖的外部库的位置和版本信息。使用pkg-config,开发人员可以很容易地查找、检索和导出这些依赖库的信息,从而简化了软件的构建过程。_ubuntu中怎么下载pkg-config
文章浏览阅读2k次。ubuntu创建共享文件夹_ubuntu20.04共享文件夹
文章浏览阅读2.9k次,点赞74次,收藏73次。对于有长期远程桌面需求的用户,建议将cpolar套餐升级到专业套餐,支持配置固定的公网TCP端口,且带宽也会相应的增大,支持更高效便捷的远程桌面连接Ubuntu系统。【cpolar内网穿透支持http/https/tcp协议,支持永久免费使用,不限制流量,无需公网IP,也不用进入路由器设置,操作简单。隧道创建成功后,点击左侧仪表盘的状态——在线隧道列表,查看xrdp隧道的所生成的公网TCP端口地址,复制下来。,使用cpolar内网穿透映射3389端口,生成公网TCP端口地址,实现在公网环境下,_ubuntu 局域网桌面
文章浏览阅读3.2k次。而在linux的ubuntu版本中,又多出两类用户:安装ubuntu系统的源用户xxx,其与root具有相同权限,仅在执行命令时,前面加sudo。在ubuntu中,用命令deluser username可以直接删除用户账号及家目录,而用centos7中的命令userdel -r username才能达到同样目的。在ubuntu中,没有moduser命令,centos7中的usermod修改用户信息的命令,同样可以用在ubuntu中。在系统中,创建新的用户或称为账号,一般需要多步操作。_ubuntu创建一个新用户
文章浏览阅读1.6w次,点赞4次,收藏23次。系统的许多日志文件都存储在 /var/log 目录中。你可以使用 ls /var/log 命令来列出可用的日志文件。/var/log/Xorg.0.log:包含 X 服务器的日志信息(图形界面)。打开DASH,搜索日志或者log,打开app,这个是/var/log的界面版。这将显示系统日志的末尾,并提供有关系统崩溃和错误的信息。/var/log/kern.log:包含内核日志信息。/var/log/dmesg:包含开机时的日志信息。/var/log/syslog:包含系统日志信息。_ubuntu查看系统日志
文章浏览阅读857次。首先将source.list复制为source.list.bak备份,然后将source.list内容改为需要的镜像源列表即可。Ubuntu采用apt作为软件安装工具,其镜像源列表记录在/etc/apt/source.list文件中。本节均为 Ubuntu 20.04 的镜像源列表。若为其他版本,将所有focal更改为其他版本代号即可。_apt 国内源