运行linux的机器死机了_如何在任何机器上轻松运行任何Linux工具

运行linux的机器死机了

by Flavio De Stefano

由弗拉维奥·德·斯特凡诺(Flavio De Stefano)

如何在任何机器上轻松运行任何Linux工具 (How to easily run any Linux tool on any machine)

Have you ever encountered a situation like the ones below?

您是否遇到过以下情况?

Situation 1: You’re on your Linux workstation, and there is a PHP code that you must execute. But this code only runs under PHP 7, and your workstation only has PHP 5.

情况1 :您在Linux工作站上,必须执行一个PHP代码。 但是此代码仅在PHP 7下运行,而您的工作站只有PHP 5。

Situation 2: You’re working on your MacBook laptop, and you desperately need your sqlmap tool from your Kali Linux distribution. But you don’t have access to your Virtual Machine.

情况2 :您正在使用MacBook笔记本电脑,并且迫切需要Kali Linux发行版中的sqlmap工具。 但是您无权访问虚拟机。

Situation 3: You’re on your Windows PC, and you immediately need an NGINX server that serves your static files from a directory.

情况3 :您在Windows PC上,立即需要一台NGINX服务器,该服务器可从目录中提供静态文件。

Situation 4: No matter which platform, you have to start your Node.js 10 project. But you don’t have Node.js installed on your platform.

情况4 :无论使用哪个平台,都必须启动Node.js 10项目。 但是您没有在平台上安装Node.js。

Or, in general, have you ever been a situation like this:

或者,总的来说,您是否遇到过以下情况:

Situation X: you are on one platform, and you immediately need a specific Linux tool, without altering your configuration or installing additional software.

情况X:您处于一个平台上,并且立即需要特定的Linux工具,而无需更改配置或安装其他软件。

All these situations can be easily solved with a single tool you may have already heard about. It works without messing up your computer by installing additional software, or editing configurations that worked for a long time.

使用您可能已经听说过的单个工具,可以轻松解决所有这些情况。 它可以通过安装其他软件或编辑长时间运行的配置而不会干扰计算机的工作。

Docker is an OS-level virtualization system. It can potentially run any binary you have in mind. Furthermore, it can run it in an isolated system, so it can’t touch your files and your precious working configurations.

Docker是操作系统级别的虚拟化系统。 它可以潜在地运行您想到的任何二进制文件。 此外,它可以在隔离的系统中运行它,因此它不会影响您的文件和宝贵的工作配置。

All you need is for someone to have already containerized your binary so that you can simply download it as an image. There are already a ton of Docker-built images out there waiting for you.

您需要做的就是让某人已经将您的二进制文件容器化,以便您可以简单地将其下载为映像。 已经有大量Docker构建的映像在等着您。

Docker does do more than this. It is a platform for developers and system administrators to develop, deploy, and run applications with containers. If you use it only to run your preferred binary, you’re using 1% of its features.

Docker所做的不只是此事。 它是开发人员和系统管理员使用容器开发,部署和运行应用程序的平台。 如果仅使用它来运行首选的二进制文件,则使用的是其功能的1%。

But let’s start from the beginning.

但是,让我们从头开始。

You can install Docker on your machine by clicking this link and selecting your platform from left menu. Then, follow the guide.

您可以通过单击此链接并从左侧菜单选择平台来在您的计算机上安装Docker。 然后,按照指南进行操作。

Once you have installed Docker, open your preferred Terminal or Command Prompt.

安装Docker后,打开您的首选终端或命令提示符。

基本概念 (Basic concepts)

First of all, let’s test if your Docker configuration is working correctly. From the terminal:

首先,让我们测试一下您的Docker配置是否正常工作。 从终端:

> docker --version
Docker version 18.03.0-ce, build 0520e24

If Docker is up and running, you should see your version number.

如果Docker已启动并正在运行,则应该看到您的版本号。

All you need now is the docker run command.

您现在所需要的就是docker run命令。

The first thing to know is the name of the image you want to use. For official images, you usually have the name of the binary with no additions.

首先要知道的是您要使用的图像的名称。 对于官方图像,通常使用二进制名称,且不添加任何名称。

For example, in the case of PHP, the image name is simply php. And what about the version? Simple as well, just add the version number (e.g., 7).

例如,对于PHP,映像名称就是php。 那版本呢? 同样简单,只需添加版本号(例如7)。

Now let’s run our first container.

现在让我们运行第一个容器。

情况1 (Situation 1)

You’re on your Linux workstation, and there is a PHP code that you must execute. But this code only runs under PHP 7, and your workstation only has PHP 5.
您在Linux工作站上,必须执行一个PHP代码。 但是此代码仅在PHP 7下运行,而您的工作站只有PHP 5。

Ok, now let’s imagine we have this simple code. It only works under PHP 7, because of the spaceship operator:

好的,现在让我们假设我们有这个简单的代码。 由于太空飞船,它只能在PHP 7下工作 操作员:

<?php echo 1 <=> 0;

How we can execute this code with Docker? Let’s build our docker run command.

我们如何使用Docker执行此代码? 让我们构建我们的docker run命令。

> docker run -it php:7
Interactive shell
php > echo 1<=>0;
1

Yes — that’s all we need!

是的,这就是我们所需要的!

The extra part is the -it flag, but that’s not difficult. Since we are in the interactive shell, it simply specifies that this container should:

额外的部分是-it标志,但这并不困难。 由于我们位于交互式外壳中,因此只需指定该容器应:

  • -t ( — tty): allocate a pseudo-TTY

    -t ( — tty) :分配一个伪TTY

  • -i ( — interactive): keep STDIN open, even if not attached

    -i ( — interactive) :保持STDIN处于打开状态,即使未连接也是如此

You should use them most of the time, with some exceptions.

除了某些例外,您应该大部分时间都使用它们。

情况二 (Situation 2)

You’re working on your MacBook laptop, and you desperately need your sqlmap tool from your Kali Linux distribution. But you don’t have access to your Virtual Machine.
您正在使用MacBook笔记本电脑,并且迫切需要Kali Linux发行版中的sqlmap工具。 但是您无权访问虚拟机。

Unfortunately, sqlmap doesn’t have an official simple image name. But maybe someone else has created an image. Let’s search for it.

不幸的是,sqlmap没有正式的简单映像名称。 但是也许其他人创造了形象。 让我们搜索一下。

> docker search sqlmap
NAME                     DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
paoloo/sqlmap            Dockered sqlmap. Build instructions: https:/…   6
k0st/alpine-sqlmap       sqlmap on alpine (size: ~113 MB)                3                                       [OK]
jdecool/sqlmap           sqlmap (Automatic SQL injection) in a contai…   2                                       [OK]
harshk13/kali-sqlmap     Kali Linux base image with Sqlmap               1
marcomsousa/sqlmap       Simple image that execute Automatic SQL inje…   1                                       [OK]
....

We have several choices. This can happen often. For most cases, the image should be the first one (or the one with the greater star count).

我们有几种选择。 这可能经常发生。 在大多数情况下,该图像应该是第一个(或具有较多星数的图像)。

Let’s use it.

让我们使用它。

> docker run -it paoloo/sqlmap --url http://localhost____ ___| |_____ ___ ___  {1.0.9.32#dev}
|_ -| . | |     | .'| . |
|___|_  |_|_|_|_|__,|  _||_|           |_|   http://sqlmap.org[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program.
...

All arguments that are after [docker run -it {image}] are passed to the binary executed in Docker, which is sqlmap in this case.

[docker run -it {image}]之后的所有参数 传递给在Docker中执行的二进制文件,在这种情况下为sqlmap。

Easy enough, right? Yes, but there is a con.

很容易,对吧? 是的,但是有一个缺点。

sqlmap writes log files onto the disk in the ~/.sqlmap path. But since Docker containers run in an isolated environment, we lose everything!!

sqlmap将日志文件写到~/.sqlmap路径中的磁盘上。 但是由于Docker容器在隔离的环境中运行,我们将失去一切!!

This is a feature, but in this case represents a bug for us — let’s fix it.

这是一项功能,但在这种情况下,对我们来说是一个错误-让我们对其进行修复。

To enable persistence so that we don’t lose that log file, we have to create a bind mount between our workstation (host) and the Docker container.

为了启用持久性以便不丢失该日志文件,我们必须在工作站(主机)和Docker容器之间创建绑定安装。

Let’s decide that our host bind mount directory is /tmp/sqlmap. This should be an empty directory created only for this purpose!

让我们决定我们的主机绑定安装目录是/tmp/sqlmap 。 这应该是一个仅为此目的而创建的空目录!

> docker run -it -v \/tmp/sqlmap:/root/.sqlmap \paoloo/sqlmap \--url http://localhost

With the -v option we’ll create a bind mount. The first argument is the host path, and the second is the path on the container that we want to map.

使用-v选项,我们将创建绑定安装。 第一个参数是主机路径,第二个参数是我们要映射的容器上的路径。

And, in fact, everything has been saved — including our reports.

而且,实际上,所有内容都已保存-包括我们的报告。

情况3 (Situation 3)

You’re on your Windows PC, and you immediately need an NGINX server that serves your static files from a directory.
您在Windows PC上,立即需要一台NGINX服务器,该服务器可从目录中提供静态文件。

As you may have noticed, the first time you run docker run, it downloads the images from the Docker Hub.

您可能已经注意到,第一次运行docker run 它将从Docker Hub下载映像。

This could be hundreds of hundreds gigabytes. This is because we downloaded the tag latest of the image (the default).

这可能是数百个千兆字节。 这是因为我们下载了图像的最新标签(默认)。

But most images have also an ‘alpine’ version of the same image. It uses Linux Alpine OS. This is an optimized version of Linux, which occupies about 130MB.

但是大多数图像也具有相同图像的“高山”版本。 它使用Linux Alpine OS。 这是Linux的优化版本,占用约130MB。

Let’s use it in this situation. We know that image name upfront is nginx (since it is an official image).

让我们在这种情况下使用它。 我们知道,图像名称的前期是nginx (因为它是官方图像)。

So the final image name will be nginx:alpine. If you want a specific version (such as 1.14), use nginx:1.14-alpine.

因此,最终的图像名称将为nginx:alpine 如果需要特定版本(例如1.14),请使用nginx:1.14-alpine.

You may have more questions. How do we know which directory the NGINX container uses to serve our files? How we know which port it exposes?

您可能还有其他问题。 我们如何知道NGINX容器使用哪个目录来提供文件? 我们如何知道它暴露哪个端口?

Luckily, the answers to all your questions are in the Docker Hub.

幸运的是,所有问题的答案都在Docker Hub中 。

So, to recap:

因此,回顾一下:

  • We have to share our directory to serve into the container. Again, this can be done using bind mounts: -v $(pwd):/usr/share/nginx/html

    我们必须共享目录才能投放到容器中。 同样,这可以使用绑定挂载完成: -v $(pwd):/usr/share/nginx/html

  • By adding :ro at the end, we are sure that container uses our files in read-only mode.

    通过在末尾添加:ro ,可以确保容器以只读模式使用文件。

  • We must bind the port exposed by the container to the host, and then communicate via TCP on our host: -p 80:80

    我们必须将容器公开的端口绑定到主机,然后在主机上通过TCP进行通信-p 80:80

> docker run \-v $(pwd):/usr/share/nginx/html:ro \-p 80:80 \nginx:alpine

情况4 (Situation 4)

No matter which platform, you have to start your Node.js 10 project. But you don’t have Node.js installed on your platform.
无论使用哪种平台,都必须启动Node.js 10项目。 但是您没有在平台上安装Node.js。

Perhaps you now understand how it works. Here, we have to share our content and bind ports.

也许您现在了解它是如何工作的。 在这里,我们必须共享我们的内容并绑定端口。

However, we don’t know the container working directory. Instead, we’re gonna explicitly set it with the -w flag to a custom directory of our choice. For example, you might choose/src — just don’t override an existing directory!

但是,我们不知道容器的工作目录。 相反,我们将使用-w标志将其显式设置为我们选择的自定义目录。 例如,您可以选择/src只是不覆盖现有目录!

> docker run \-p 3000:3000 \-v $(pwd):/src \-w /src \node:10-alpine \node main.js
Example app listening on port 3000!
...

Simple and powerful enough?

简单而强大?

Additionally, do you want a ‘shortcut’ to just execute binaries without searching for third-party images?

另外,您是否希望“快捷方式”仅执行二进制文件而不搜索第三方图像?

Why don’t you try my simple tool DR?

您为什么不尝试使用我的简单工具DR ?

I hope that you’re gonna use Docker for all your future binaries! :)

希望您将来使用Docker编写所有二进制文件! :)

翻译自: https://www.freecodecamp.org/news/how-to-run-any-binary-of-any-platform-without-messing-up-with-your-workstation-dade18c18801/

运行linux的机器死机了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392721.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【实战】烂泥:一次纠结的系统安装

这应该是昨天的事了&#xff0c;因为昨天太忙了&#xff0c;就没有贴出来&#xff0c;今天下午我想了想还是贴出来吧。一是给自己一个提醒&#xff0c;二是也给坛子里面的午饭们再以后安装系统中提供一种思路。 环境&#xff1a;thinkpad x100e笔记本&#xff0c;2G内存&#x…

Android动态改变TextView字体颜色

Android动态改变TextView字体颜色 分类&#xff1a; Android 2012-06-04 21:56 141人阅读 评论(0) 收藏 举报androidcolorslayout必须在在res/color文件夹下面创建一个selector的xml [html] view plaincopyfont_style_colors.xml <selector xmlns:android"http://…

关于小程序的一些坑的总结

最近开发的小程序&#xff0c;有很多的坑。 1.底部的tabbar 不可更改尺寸和字体的大小。限制的还是蛮死的&#xff01;不知道是不是我没找到方法去修改还是咋的。淡淡的忧桑&#xff5e;&#xff5e;&#xff5e; 2.可以动态的设置小程序的顶部导航栏的字&#xff0c;但是不可…

开源项目贡献者_如何认识您的开源项目贡献者并发展您的社区

开源项目贡献者by David Herron大卫赫伦(David Herron) 如何认识您的开源项目贡献者并发展您的社区 (How to recognize your open source project contributors and grow your community) There’s a truism — if a community is not growing, it is slowly dying. How is yo…

华农java实验7_国家实验教学示范中心

我校有生物学实验教学中心、作物学实验教学中心、水产养殖实验教学中心、动物医学实验教学中心4个国家级实验教学示范中心&#xff0c;10个省级实验教学示范中心。生物学实验教学中心华中农业大学生物学实验教学中心成立于2001年7月&#xff0c;是直属于生命科学技术学院的校级…

jsonpickle数据序列化

json&pickle数据序列化 json 用于字符串和python数据类型间进行转换 pickle 用于python特有的类型 和 python的数据类型间进行转换序列化&#xff1a;把字典或者字符串的内存对象 存到硬盘上&#xff1b; 反序列化&#xff1a;就是从硬盘上加载出来 json序列化与反序列化…

array_walk与array_map的区别

1.array_walk是用于用户自定义的函数&#xff0c;所以想用array_walk($aIds, "trim");去掉数据元素中的空格是达不到目的的只能用array_walk($aIds, create_function(&$val, $val trim($val);)); 2.想完成上边的需求其实更加合适用$aNewIds array_map("t…

shopify二次开发教程_详细教程:如何将Shopify的Storefront API与React和Redux结合使用...

shopify二次开发教程by Chris Frewin克里斯弗里温(Chris Frewin) 详细教程&#xff1a;如何将Shopify的Storefront API与React和Redux结合使用 (A detailed tutorial: how to use Shopify’s Storefront API with React and Redux) 电子商务为所有人&#xff01; (…网站&…

element里面popover里面的高度_五斗柜的高度一般是多少 五斗柜放在什么位置好

五斗柜也就是一种抽屉收纳柜&#xff0c;目前在卧室或是书房等空间均是可以见到。其根据使用用途的不同&#xff0c;进而有着高度和款式&#xff0c;以及摆放位置等等的区别。因此&#xff0c;下面带来五斗柜的高度一般是多少、五斗柜放在什么位置好&#xff0c;以及五斗柜里面…

leetcode 57. 插入区间

给出一个无重叠的 &#xff0c;按照区间起始端点排序的区间列表。 在列表中插入一个新的区间&#xff0c;你需要确保列表中的区间仍然有序且不重叠&#xff08;如果有必要的话&#xff0c;可以合并区间&#xff09;。 示例 1&#xff1a; 输入&#xff1a;intervals [[1,3]…

《C++标准程序库》学习笔记1--第二章第三章

————————— 第二章 —————————1.&#xff08;P11&#xff09; C规定&#xff1a;除了以typename修饰外&#xff0c;template内的任何标志符号都被视为一个值(value)而非一个型别。 eg. template <classT>classMyClass{ typename T::SubType *ptr; };…

让物联网真正起飞的关键:无线充电

从一般郊区家庭到工厂装配生产线&#xff0c;我们生活中的每个角落都正在经历“智能”技术强化的过程。物联网&#xff08;IoT&#xff09;技术看似无所不在&#xff0c;但是为这些装置持续供电仍是一大挑战&#xff0c;除非这个问题能够解决&#xff0c;否则许多令人兴奋的物联…

【NOIP2016】愤怒的小鸟

题目描述 Kiana最近沉迷于一款神奇的游戏无法自拔。 简单来说&#xff0c;这款游戏是在一个平面上进行的。 有一架弹弓位于(0,0)处&#xff0c;每次Kiana可以用它向第一象限发射一只红色的小鸟&#xff0c;小鸟们的飞行轨迹均为形如的曲线&#xff0c;其中a,b是Kiana指定的参数…

leetcode 127. 单词接龙(bfs)

给定两个单词&#xff08;beginWord 和 endWord&#xff09;和一个字典&#xff0c;找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则&#xff1a; 每次转换只能改变一个字母。 转换过程中的中间单词必须是字典中的单词。 说明: 如果不存在这样的转换序…

java swing 动态生成表格_6 个曾经牛逼哄哄的 Java 技术,你用过吗?

大家好啊&#xff0c;今天给大家分享下我的开发历程中&#xff0c;我知道的那些被淘汰的技术或者框架&#xff0c;有些我甚至都没有用过&#xff0c;但我知道它曾经风光过。废话不多说&#xff0c;下面我要开始吹了……1、Swing下面这个是用 swing 开发的&#xff1a;Swing 算是…

如果您是JavaScript开发人员,为什么要进行增强现实-以及如何开始

by Evaristo Caraballo通过Evaristo Caraballo 如果您是JavaScript开发人员&#xff0c;为什么要进行增强现实-以及如何开始 (Why you should do Augmented Reality if you are a JavaScript developer — and how to start) If you are a JavaScript coder who is still late…

[Java 安全]加密算法

Base64编码 算法简述 定义 Base64内容传送编码是一种以任意8位字节序列组合的描述形式&#xff0c;这种形式不易被人直接识别。 Base64是一种很常见的编码规范&#xff0c;其作用是将二进制序列转换为人类可读的ASCII字符序列&#xff0c;常用在需用通过文本协议&#xff08;比…

hdu5299 Circles Game

题意是这样。给出非常多圆&#xff0c;要么两两相离&#xff0c;要么包括&#xff0c;若删掉一个圆&#xff0c;那被他包括的都要删除&#xff0c;若某人没有圆给他删&#xff0c;那么他就赢了。 。。。知道树上博弈的话。就非常easy。。。不知道的话。这确实是个神题…… 按半…

leetcode 1356. 根据数字二进制下 1 的数目排序(排序)

给你一个整数数组 arr 。请你将数组中的元素按照其二进制表示中数字 1 的数目升序排序。 如果存在多个数字二进制中 1 的数目相同&#xff0c;则必须将它们按照数值大小升序排列。 请你返回排序后的数组。 示例 1&#xff1a; 输入&#xff1a;arr [0,1,2,3,4,5,6,7,8] 输…

oracle java认证_如何通过Oracle的Java认证-开发人员实用指南

oracle java认证by javinpaul由javinpaul 如何通过Oracle的Java认证-开发人员实用指南 (How to Pass Oracle’s Java Certifications — a Practical Guide for Developers) A Java certification is highly regarded in the IT Industry and provides a Java developer with …