by Ryan Gordon

通过瑞安·戈登(Ryan Gordon)

在Raspberry Pi上设置Docker的简单方法 (The easy way to set up Docker on a Raspberry Pi)

Docker is a very useful tool for running containerized versions of popular applications (such as databases) or setting up some IoT service on an internet-connected device.

Docker是运行常用应用程序的容器化版本(例如数据库)或在连接互联网的设备上设置某些IoT服务的非常有用的工具。

But installing Docker can sometimes be a hassle if it needs to be done a number of times across different computers. The silver lining, however, is that there is a handy trick hidden away in the Docker docs detailing how to install Docker with just two lines in the terminal.

但是,如果需要在不同的计算机上多次安装Docker,有时可能会很麻烦。 然而,一线希望是,在Docker文档中隐藏了一个方便的技巧,详细介绍了如何在终端中仅用两行安装Docker。

Yes, you heard right! With just two lines you can load and install Docker.

是的,您没听错! 仅需两行,您就可以加载和安装Docker。

Installing Docker can be handled by a bash script which will automate the entire installation. Docker provides such a script at get.docker.com . The first command will be consuming this URL, looking for a file called get-docker.sh . Once gotten, we just run the script. The two commands can be chained together to form a statement like:

可以通过bash脚本处理Docker的安装,该脚本将自动完成整个安装过程。 Docker在get.docker.com提供了这样的脚本。 第一个命令将使用此URL,查找名为get-docker.sh的文件。 一旦获得,我们就运行脚本。 这两个命令可以链接在一起形成如下语句:

curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

Now you have Docker installed, and the installation only took two lines.

现在您已经安装了Docker,并且安装仅需两行。

As you just saw, the two commands above are chained together using the ‘&&’ operator. This means that the commands will run one after the other, but can be typed on the same line.

如您所见,上面的两个命令使用'&&'运算符链接在一起。 这意味着命令将一个接一个地运行,但可以在同一行上键入。

One small issue, though, is that you might experience difficulty running Docker commands without sudo. This can be fixed, but it’ll take a few more lines.

但是,一个小问题是,如果没有sudo,运行Docker命令可能会遇到困难。 可以解决此问题,但需要多花费几行。

如何设置Docker始终不使用sudo运行 (How to set up Docker to run without using sudo all the time)

I discovered this solution on AskUbuntu after encountering the problem. Let’s go through it now.

遇到问题后,我在AskUbuntu上发现了此解决方案。 让我们现在来看一下。

共有3个步骤: (There are 3 steps:)

  1. Add the Docker group if it doesn’t already exist:添加Docker组(如果尚不存在):
sudo groupadd docker

2. Add the connected user “$USER” to the docker group. Change the user name to match your preferred user if you do not want to use your current user:

2.将连接的用户“ $ USER”添加到泊坞窗组。 如果您不想使用当前用户,请更改用户名以匹配您的首选用户:

sudo gpasswd -a $USER docker

3. From here you have two options: either logout and then log back in, or run newgrp docker for the changes to take effect.

3.在这里,您有两个选择:注销然后重新登录,或者运行newgrp docker使更改生效。

You should now be able to run Docker without sudo. To test, try this:

您现在应该可以在没有sudo的情况下运行Docker。 要测试,请尝试以下操作:

docker run hello-world

If it worked, you should see a lovely message from Docker:

如果可行,您应该会从Docker看到一条可爱的消息:

Again, all credit for this solution goes to this great AskUbuntu answer I found. Without typing sudo all the time, commands will be much easier to work with.

同样,此解决方案的全部功劳归功于我找到的这个出色的AskUbuntu答案。 无需一直输入sudo,命令将更容易使用。

但是,等等,还有更多! (But wait, there’s more!)

What if you want docker-compose also? You could try and install the docker-compose source similarly to how we installed Docker. One interesting approach I found on the Google Cloud Engines docs is that you can actually run docker-compose as a container itself!

如果您还想要docker-compose怎么办? 您可以尝试像安装Docker一样安装docker-compose源代码。 我在Google Cloud Engines文档中发现的一种有趣的方法是,您实际上可以将docker-compose作为容器本身运行!

Doing so means you have a disposable installation of docker-compose which will be used to compose your services. At any point, you can throw it away and repeat the steps for a fresh docker-compose.

这样做意味着您可以一次性安装docker-compose,它将用于组成您的服务。 在任何时候,您都可以将其丢弃,并重复执行新的docker-compose的步骤。

First step will be running docker-compose as a container and giving it access to volumes.

第一步将作为容器运行docker-compose,并授予其访问卷的权限。

docker run \    -v /var/run/docker.sock:/var/run/docker.sock \    -v "$PWD:/rootfs/$PWD" \    -w="/rootfs/$PWD" \    docker/compose:1.13.0 up

Next, make an alias to docker compose:

接下来,为docker compose做一个别名:

echo alias docker-compose="'"'docker run \    -v /var/run/docker.sock:/var/run/docker.sock \    -v "$PWD:/rootfs/$PWD" \    -w="/rootfs/$PWD" \    docker/compose:1.13.0'"'" >> ~/.bashrc

Then reload bash:

然后重新加载bash:

source ~/.bashrc

Now you have full access to docker-compose. The alias defined above means that rather than having to type out docker commands when you want to use the compose container, you can just use ‘docker-compose’ as you normally would.

现在您可以完全访问docker-compose。 上面定义的别名意味着,当您要使用compose容器时,不必不必键入docker命令,而可以像平常一样使用“ docker-compose”。

关于RPi上Docker的重要通知 (Important Notice about Docker on RPi)

Raspberry Pi’s use ARM archetecture, and as a result wont be compatible with all containers out of the box. Images will need to be built from an ARM base image.

Raspberry Pi使用ARM架构,因此无法与所有开箱即用的容器兼容。 映像将需要从ARM基本映像构建。

You can see this in action by running a containerized Redis instance on a Raspberry Pi (which is quite relevant to an upcoming series I’m writing). Doing so will require working with a base image. Provided we use an ARM-compatible image, no problems should arise. The issue is finding a well-maintained one.

您可以通过在Raspberry Pi上运行容器化的Redis实例(这与我正在编写的下一个系列非常相关)来看到实际的效果。 这样做将需要使用基础图像。 只要我们使用兼容ARM的映像,就不会出现问题。 问题是找到一个维护良好的设备。

If you enjoyed this article, give it a clap.

如果您喜欢这篇文章,请拍一下。

I have other posts on my page related to Microservices, Ionic, and more.

我的页面上还有其他与微服务,Ionic等相关的帖子。

翻译自: https://www.freecodecamp.org/news/the-easy-way-to-set-up-docker-on-a-raspberry-pi-7d24ced073ef/

在Raspberry Pi上设置Docker的简单方法相关推荐

  1. raspberry pi_在Raspberry Pi上试用Docker

    raspberry pi 在Opensource.com上,我可以在日常工作中了解很多非常有趣的新兴技术. 但是我并不总是可以自己深入研究它们. 在过去的这个周末,我留出了一些时间来做. 几年来,我一 ...

  2. 如何在Raspberry Pi上设置两因素身份验证

    Kiklas/ShutterstockKiklas /快门 The Raspberry Pi is everywhere now, which is why it's caught the eye o ...

  3. 如何在5美元的Raspberry Pi上构建个人开发服务器

    In this article, you'll learn how to build a personal dev server by installing Git, Node.js, Rust, a ...

  4. 在Raspberry Pi上轻松设置.NET Core并使用VS Code进行远程调试

    目录 介绍 背景 工具选择 先决条件 准备SD卡 SSH配置和.NET安装 示例程序 兴趣点 带有最新代码的GitHub存储库 介绍 手动设置了用于.NET Core和远程调试的Raspberry P ...

  5. raspberry pi_如何在Raspberry Pi上使用LÖVE游戏引擎对游戏进行编程

    raspberry pi Raspberry Pi以向孩子介绍开源软件和编程而闻名. Pi是负担得起的,实用的专业级计算入门,伪装成可破解的乐趣. Mitch Resnick's Scratch (最 ...

  6. (四)Raspberry Pi上的人工智能人脸检测

    目录 介绍 在Raspberry Pi上安装组件 在Raspberry Pi上运行检测器 性能注意事项 下一步 在这里,我们解释了用于人脸识别的简单人脸数据库的结构,然后开发了将人脸添加到人脸数据库的 ...

  7. 边缘设备上的实时AI人员检测:在Raspberry Pi上启动SSD

    下载数据-19.3 MB 下载模型-43.5 MB 下载结果-36.66 MB 在本系列的最后一篇文章中,我们编写了Python代码,用于使用SSD模型检测图像中的人物.在本文中,我们将介绍在Rasp ...

  8. 如何在 Raspberry Pi 上快速安装 Oracle Linux ?

    你知道树莓派(Raspberry Pi)吗?它可不是一款餐后甜点,而是一个只有信用卡大小的计算机,更准确的说它是一款单板计算机.那么,如何简单快速地在上面安装 Oracle Linux?下面将会详细介 ...

  9. 在Raspberry Pi上安装HDMI-CEC

    转自https://www.labno3.com/2021/02/01/using-hdmi-cec-on-a-raspberry-pi/ HDMI-CEC是一种特殊的协议,用于电视与另一个设备通过H ...

最新文章

  1. Delphi下利用WinIo模拟鼠标键盘详解
  2. 解决element-ui表头错位的问题
  3. 881.BoatstoSavePeople
  4. QPG分布框架1.1.1
  5. opencv基本绘图函数--点,线,矩形,圆等
  6. 北大学子求职经历与建议(IT类) 收藏
  7. 驱动人生解锁“C盘瘦身”功能,助力电脑快速运行
  8. WinRunner的工作流程
  9. 应用系统开发--银行系统
  10. 解释计算机网络英文缩写CA,计算机网络名词英文缩写
  11. php httprequest 415,http post 415错误的解决方法
  12. WiFi 802.11可调参数说明---分片阈值(fragmentation threshold)
  13. Codeforces Gym 100339B Diversion 树形DP + LCA
  14. 在html中让图片旋转180度,gif图片旋转教程:怎么把gif旋转90度/180度 附gif图片旋转软件...
  15. java 三点定位_GPS定位系统(三)——Java后端
  16. MySql安装教程与HeidiSQL管理工具使用方法、HeidiSQL中SQL语句使用(六)
  17. MongoDB数据库设计中6条重要的经验法则(一)
  18. OGM 与mongodb
  19. stc12c5a60s2c语言程序,单片机STC12C5A60S2控制AT24C04的程序(C语言)
  20. 数据分析--DataFrame(4)

热门文章

  1. ListView控件获取选中项的内容 c# 114867417
  2. 案例 员工演奏乐器 c# 1614191419
  3. 前端开发 常用选择符与权重0229
  4. 洛谷——P1478 陶陶摘苹果(升级版)
  5. IP釋放、清除、以及刷新DNS
  6. macOS卸载Java9及利用Homebrew搭建并配置Java开发环境
  7. PHPUnit-断言
  8. Web报表工具FineReport填报界面键盘操作
  9. [转] Java中的容器
  10. cacti登录密码忘记解决方法